• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Drop down selections to emails

Explorer ,
Nov 15, 2021 Nov 15, 2021

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.

TOPICS
Acrobat SDK and JavaScript

Views

1.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 15, 2021 Nov 15, 2021

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});

Votes

Translate

Translate
Community Expert ,
Nov 15, 2021 Nov 15, 2021

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});

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 16, 2021 Nov 16, 2021

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 16, 2021 Nov 16, 2021

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 16, 2021 Nov 16, 2021

Copy link to clipboard

Copied

I dont get any errors it contunies to the email screnn but there is nothing in the email body

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 16, 2021 Nov 16, 2021

Copy link to clipboard

Copied

Is the value of the field "No" or "NO"? JavaScript is case-sensitive...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 16, 2021 Nov 16, 2021

Copy link to clipboard

Copied

the value in the field in "No" and i have changed the code to suit

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 16, 2021 Nov 16, 2021

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"

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 16, 2021 Nov 16, 2021

Copy link to clipboard

Copied

Did you check the Console window?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 16, 2021 Nov 16, 2021

Copy link to clipboard

Copied

What should I be checking for in the console window?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 17, 2021 Nov 17, 2021

Copy link to clipboard

Copied

Any error messages...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 17, 2021 Nov 17, 2021

Copy link to clipboard

Copied

What script does you use?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 22, 2021 Nov 22, 2021

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})
}
;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 22, 2021 Nov 22, 2021

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";

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 22, 2021 Nov 22, 2021

Copy link to clipboard

Copied

Hello,

Sorry I dont quite understand what you mean?

Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 22, 2021 Nov 22, 2021

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 22, 2021 Nov 22, 2021

Copy link to clipboard

Copied

so if I change all of the "else ifs" to just "if" this will work?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 22, 2021 Nov 22, 2021

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 22, 2021 Nov 22, 2021

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"

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 22, 2021 Nov 22, 2021

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 22, 2021 Nov 22, 2021

Copy link to clipboard

Copied

Change:

emailBody =

To:

emailBody +=

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 22, 2021 Nov 22, 2021

Copy link to clipboard

Copied

If you want to add a line-break between each line use this:

 

emailBody += "\n ...";

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 22, 2021 Nov 22, 2021

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 22, 2021 Nov 22, 2021

Copy link to clipboard

Copied

Duplicate the "\n" character.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 22, 2021 Nov 22, 2021

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 +="";
 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines