Copy link to clipboard
Copied
Hello,
If i have a drop down that has yes and no in it can I adjust the email body to show pre determined information if no is selected?
i.e.
Are there scratches in panel work? "NO"
Email body: Warning, there are scratches in panel work
etc.
You can use something like this:
var emailBody = "";
if (this.getField("Are there scratches in panel work?").valueAsString=="NO")
emailBody = "Warning, there are scratches in panel work";
this.mailDoc({cTo: "me@server.com", cSubject: "Email subject goes here", cMsg: emailBody});
Copy link to clipboard
Copied
You can use something like this:
var emailBody = "";
if (this.getField("Are there scratches in panel work?").valueAsString=="NO")
emailBody = "Warning, there are scratches in panel work";
this.mailDoc({cTo: "me@server.com", cSubject: "Email subject goes here", cMsg: emailBody});
Copy link to clipboard
Copied
Hello,
I cant seem to get it to work, it will email if the box is set to Yes however when set to No it will not submit?
also, is this method stackable i.e. if serveral selections are set to No will it put multi lines into the email?
Copy link to clipboard
Copied
Are there any errors in the JS Console when you use it?
And yes, you can create multiple conditions, adding different texts to the email body string in each one.
Copy link to clipboard
Copied
I dont get any errors it contunies to the email screnn but there is nothing in the email body
Copy link to clipboard
Copied
Is the value of the field "No" or "NO"? JavaScript is case-sensitive...
Copy link to clipboard
Copied
the value in the field in "No" and i have changed the code to suit
Copy link to clipboard
Copied
Apologies, it does not go to the email screen, nothing happens when one of the boxes is set to "No"
Copy link to clipboard
Copied
Did you check the Console window?
Copy link to clipboard
Copied
What should I be checking for in the console window?
Copy link to clipboard
Copied
Any error messages...
Copy link to clipboard
Copied
What script does you use?
Copy link to clipboard
Copied
var emailBody = "";
if (this.getField("1").valueAsString=="No")
emailBody = "Warning, there are scratches in panel work";
else if(this.getField("Serial No").value == "")
{
app.alert("Serial Number must be filled in");
}
else if(this.getField("Tyres").value == " ")
{
app.alert("Tyre size not selected");
}
else if(this.getField("Dropdown1").value == " ")
{
app.alert("Axle config not selected");
}
else if(this.getField("1").value == " ")
{
app.alert("Drawbar assembely cannot be left blank");
}
else if(this.getField("2").value == " ")
{
app.alert("Drawbar bolt kit cannot be left blank");
}
else if(this.getField("3").value == " ")
{
app.alert("Bale chute kit cannot be left blank");
}
else if(this.getField("4").value == " ")
{
app.alert("Computer kit cannot be left blank");
}
else if(this.getField("5").value == " ")
{
app.alert("C1000 harness cannot be left blank");
}
else if(this.getField("6").value == " ")
{
app.alert("Lighting/ Brake Harness kit cannot be left blank");
}
else if(this.getField("7").value == " ")
{
app.alert("Wide load boards cannot be left blank");
}
else if(this.getField("8").value == " ")
{
app.alert("Wide load board brakets cannot be left blank");
}
else if(this.getField("9").value == " ")
{
app.alert("Knotter flag kit cannot be left blank");
}
else if(this.getField("10").value == " ")
{
app.alert("Spares kits cannot be left blank");
}
else if(this.getField("11").value == " ")
{
app.alert("2290 Ladder kit cannot be left blank");
}
else if(this.getField("12").value == " ")
{
app.alert("pick up wheels cannot be left blank");
}
else if(this.getField("13").value == " ")
{
app.alert("Saftey Chain cannot be left blank");
}
else if(this.getField("14").value == " ")
{
app.alert("Beacon kit cannot be left blank");
}
else if(this.getField("15").value == " ")
{
app.alert("Operators manual cannot be left blank");
}
else if(this.getField("16").value == " ")
{
app.alert("EU Conformity cannot be left blank");
}
else
{// All is ok
this.mailDoc({cTo: "Email 1", cCc:"Email 2", cSubject: this.getField("Serial No").valueAsString, cMsg: emailBody})
}
;
Copy link to clipboard
Copied
At the first if you set emailBody without sending the email:
if (this.getField("1").valueAsString=="No")
emailBody = "Warning, there are scratches in panel work";
Copy link to clipboard
Copied
Hello,
Sorry I dont quite understand what you mean?
Thanks
Copy link to clipboard
Copied
Because you used an if-else if-else construction, only in the very last condition, if all the previous ones were false, will the mailDoc command execute, which means that the emailBody variable will always be empty.
You need to decide how it should work and then build the logic of the code based on that. If you want to allow mailing the form even if field "1" is "No" then don't put an "else" after that condition. If you don't want to allow sending it in that scenario then there's no point in setting the emailBody variable to the warning message you specified.
Copy link to clipboard
Copied
so if I change all of the "else ifs" to just "if" this will work?
Copy link to clipboard
Copied
Again, you need to first describe how it should work. Do you want to prevent sending the form if any of these conditions is true, or do you just want to display an alert, but then allow it to send anyway?
Copy link to clipboard
Copied
I would like it to send anyway but make a note on the email of all of the boxes that have been checked as "NO"
Copy link to clipboard
Copied
ok i changes the values of "Else if" to "if" and this does what i need it to do! how do i now go about stacking the no answers in the email? I would assume if i were just to put:
if (this.getField("1").valueAsString=="No")
emailBody = "Warning, there are scratches in panel work";
if (this.getField("2").valueAsString=="No")
emailBody = "PTO missing";
this will clear the previous information and place the newest into the email?
Copy link to clipboard
Copied
Change:
emailBody =
To:
emailBody +=
Copy link to clipboard
Copied
If you want to add a line-break between each line use this:
emailBody += "\n ...";
Copy link to clipboard
Copied
Excellent, that seems to work, last thing is how do I make it put it on the next line rather than straight after the first one?
Copy link to clipboard
Copied
Duplicate the "\n" character.
Copy link to clipboard
Copied
This works perfectly! thank you very much!!
Is there a way to add information from a text box if it has been filled in too?
I have tried the following code:
if (this.getField("Text3").valueAsString
emailBody +="";