Dynamic Email Button, problem with invalid email - Please help!
I’m having a problem setting up my dynamic email button. It works fine if I use an email address without dashes (eg. smitht@dsv.org), but when I use the email addresses as shown below with a dash I get an ‘Invalid Email’ Warning. I don’t know how to set it up as that is how the emails are supposed to be and I don’t know how to resolve it. I have documented the script I have. Any help would be appreciated. Thank you!!
//Submit button Actions Run a Script
if(ValidFields())
{
var cToAddr = this.getField("ForemanEmail").value;
// Set the subject line
var cSubLine = "eDAC "
+ this.getField("Date").value + " "
+ this.getField("CrewName").value;
var cBody = "Thank you for submitting your timesheet.\n" +
"Please save a copy for your records";
this.mailDoc({bUI:true, cTo: cToAddr, cSubject: cSubLine,
cMsg: cBody});
}
//ForemanEmail Text Field Custom Keystroke Script
var rxp = /^\s*(\w+(\.\w+)*@(\w+\.)+\w{2,3})\s*$/;
if(event.willCommit && (event.value != "") )
{
if(event.rc = rxp.test(event.value))
event.value = RegExp.$1
else
app.alert("Invalid Email",1);
}
//Document JavaScript Submit Button
function ValidFields()
{
var bRtn = false;
var aErrMsg = [];
var rgEmpty = /^\s*$/;
if(rgEmpty.test(this.getField("Date").value))
aErrMsg.push("Work Date Field");
if(rgEmpty.test(this.getField("CrewName").value))
aErrMsg.push("Crew Name");
if(rgEmpty.test(this.getField("ForemanEmail").value))
aErrMsg.push(" ");
if(aErrMsg.length == 0)
bRtn = true;
else
app.alert("Error\nOne or more required fields have not been filled out:\n\n * " + aErrMsg.join("\n * "));;
return bRtn;
}
//Document Javascript Init
this.getField("general_document_date_today").value = new Date();
//Document JavaScript populate data from Crew dropdown list to ForemanEmail and CrewName text fields
var EmailData = { "Maintenance":{ Email: "Roads-Concrete-2@dsv.org",
CrewName: "Maintenance" },
"Concrete":{ Email: "Roads-Maint-Foreman@dsv.org",
CrewName: "Concrete" },
"Asphalt" :{ Email: "Roads-Concrete-Foreman@dsv.org",
CrewName: "Asphalt" }};
function SetFieldValuesEmail(cEmailName)
{
this.getField("ForemanEmail").value = EmailData[cEmailName].Email;
this.getField("CrewName").value = EmailData[cEmailName].CrewName;
}
//Crew dropdown text field Custom Keystroke to populate data to ForemanEmail and CrewName text fields
if( event.willCommit )
{
if(event.value == " ")
this.resetForm(["ForemanEmail","CrewName"]);
else
SetFieldValuesEmail(event.value);
}
