Skip to main content
gregs50739865
Participating Frequently
May 3, 2019
Answered

If Else based of user selected fields

  • May 3, 2019
  • 3 replies
  • 796 views

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

This topic has been closed for replies.
Correct answer try67

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

3 replies

try67
Community Expert
Community Expert
May 3, 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.

Bernd Alheit
Community Expert
Community Expert
May 3, 2019

Remove var before cSubLine and cBody.

try67
Community Expert
Community Expert
May 3, 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?

gregs50739865
Participating Frequently
May 3, 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”;

}

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
May 3, 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});