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});
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});
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?
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”;
}
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});
Copy link to clipboard
Copied
Awesome! That worked! You folks kick butts! Thank you so much!
Copy link to clipboard
Copied
Remove var before cSubLine and cBody.
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.