If Else based of user selected fields

New Here ,
May 03, 2019

Copy link to clipboard

Copied

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

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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

TOPICS
Acrobat SDK and JavaScript, Windows

Views

72

Likes

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

If Else based of user selected fields

New Here ,
May 03, 2019

Copy link to clipboard

Copied

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

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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

TOPICS
Acrobat SDK and JavaScript, Windows

Views

73

Likes

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
May 03, 2019 0
Most Valuable Participant ,
May 03, 2019

Copy link to clipboard

Copied

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?

Likes

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
Reply
Loading...
May 03, 2019 0
New Here ,
May 03, 2019

Copy link to clipboard

Copied

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

}

Likes

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
Reply
Loading...
May 03, 2019 0
Most Valuable Participant ,
May 03, 2019

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
May 03, 2019 0
New Here ,
May 03, 2019

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
May 03, 2019 0
Adobe Community Professional ,
May 03, 2019

Copy link to clipboard

Copied

Remove var before cSubLine and cBody.

Likes

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
Reply
Loading...
May 03, 2019 0
Most Valuable Participant ,
May 03, 2019

Copy link to clipboard

Copied

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.

Likes

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
Reply
Loading...
May 03, 2019 0