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

If Else based of user selected fields

New Here ,
May 03, 2019 May 03, 2019

Hello,

Looking for some help with If Else statements in a PDF. What I would like to accomplish is changing the wording of an email subject and body based off the user choices in a drop down.

Basically if the user selects "yes" from a dropd own titled "Repair Req" when they need a repair request when submitting the form, the email subject line and body wording will change. If the user selects "no", then the subject and body are different.

var cToAddr = “user1@email.com”;

var cCCAddr = "user2@email.com;

if(this.getField("Repair Req").value!="Yes") {

var cSubLine = "FINAL w/ REPAIR REQUEST“;

var cBody = "Repair Request”;

}

else{

var cSubLine = "FINAL";

var cBody = "Final”;

}

this.mailDoc({bUI:true, cTo: cToAddr, cCc: cCCAddr, cSubject: cSubLine, cMsg: cBody});

TOPICS
Acrobat SDK and JavaScript , Windows
709
Translate
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 , May 03, 2019 May 03, 2019

Well, you've introduced another error in this version.

Use this code:

var cToAddr = "user1@email.com";

var cCCAddr = "user2@email.com";

var cSubLine, cBody;

if (this.getField("Repair Req").value=="Yes") {

    cSubLine = "FINAL w/ REPAIR REQUEST";

    cBody = "Repair Request";

} else {

    cSubLine = "FINAL";

    cBody = "Final";

}

this.mailDoc({bUI:true, cTo: cToAddr, cCc: cCCAddr, cSubject: cSubLine, cMsg: cBody});

Translate
Community Expert ,
May 03, 2019 May 03, 2019

Your code looks almost fine, and I believe it should work despite the issues of where you're declaring the variables in it, because JS is very lenient with that. Is it not working?

Translate
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
New Here ,
May 03, 2019 May 03, 2019

No...it doesnt...I am not well versed in JS at all...so I am feeling my way through. I have tried removing the "!" in the if statement and when the user hits the submit button it changes the value of the Repair Request drop down from "No" to "Yes".

if(this.getField("Repair Req").value="Yes") {

var cSubLine = "FINAL w/ REPAIR REQUEST“;

var cBody = "Repair Request”;

}

else{

var cSubLine = "FINAL";

var cBody = "Final”;

}

Translate
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 ,
May 03, 2019 May 03, 2019

Well, you've introduced another error in this version.

Use this code:

var cToAddr = "user1@email.com";

var cCCAddr = "user2@email.com";

var cSubLine, cBody;

if (this.getField("Repair Req").value=="Yes") {

    cSubLine = "FINAL w/ REPAIR REQUEST";

    cBody = "Repair Request";

} else {

    cSubLine = "FINAL";

    cBody = "Final";

}

this.mailDoc({bUI:true, cTo: cToAddr, cCc: cCCAddr, cSubject: cSubLine, cMsg: cBody});

Translate
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
New Here ,
May 03, 2019 May 03, 2019
LATEST

Awesome! That worked! You folks kick butts! Thank you so much!

Translate
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 ,
May 03, 2019 May 03, 2019

Remove var before cSubLine and cBody.

Translate
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 ,
May 03, 2019 May 03, 2019

Ah, I'm noticing two errors now that will stop it from working.

In the first line you're using non-conventional quotes. You must only use straight quotes.

And in the second line you're missing the closing quotes after the email address.

Both errors should cause an error message to appear in the JS Console when you try to run the code, though.

Translate
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