I've created a form with a Submit button that generates an email with the form an attachment. The trouble is if there's a blank field, the email contains the value "null" where I'd like it to remain blank. How can I format the javascript shown below to allow blank fields to remain blank in the email and not display as "null".?
Solved! Go to Solution.
Views
Replies
Total Likes
Just syntax issues, the main issue is you have =+ ( which is assignment) instead of += (which is concat). Correct one should be +=
Views
Replies
Total Likes
Try using formattedValue instead of rawValue (if the field doesnt have some strange display pattern that is).
Views
Replies
Total Likes
Thank you for this lesson. What might have been an easy solution for you was wracking my brain...I'm still just getting started here
Can I ask one follow-on question? Is there a way to have written each of these lines so that if there isn't a particular datapoint that the line doesn't show up in my results email? So, if the Organization field is blank, or null, then don't even provide a blank Organization line in the response email?
Views
Replies
Total Likes
Only way would be to check each of the values before you build part of your string, for example:
function GetBody()
{
var body = "Non-Core Software Request Form\n\n"
+ " **** User Information ****\n";
if ( ! form1.Page1.RequestorName.isNull() )
body += "Requestor: " + form1.Page1.RequestorName.rawValue + "\n";
...
}
and keep going for each one. You may need an if statement for all fields being null depending if your form can allow that.
In applying this to the form, it appears to pass the "Check Script Syntax" feature but when I press the submit button with this change, nothing happens. If I remark it out, it works as before and I get the email message with the form attached. This form has about 50 similar fields, all connected by a similar series of sections like I showed in the original message so once I get one field figured out, the rest should follow easily.
Thanks.
Views
Replies
Total Likes
Sorry it should be isNull and not isNull()
I was able to get it working a little better but it's still not quite right.
What happens now is if I enter data in the field, it shows up (sorta) but everything before or after it does not. It the field is left blank, then the first two lines of text shown in your reply above in RED and between the quotes will appear. If for instance, if I enter "Jim Dandy" in the Requetor Field the only thing in the body of the email is shown below. If I leave it blank then I get the lines "Non-Core..." and *** User Info..." shown above but nothing else.
The result looks like this:
NaNJim Dandy
I'm not sure where NaN portion comes from...
Views
Replies
Total Likes
Sounds like you have the body variable in an if statement which isnt executing correctly, and probably that if statement condition should be reversed. NaN is coming because you dont have an initial value for body at all so when you do body += "Jim Dandy", you will get NaNJimDandy. Can you post the script for the if statement?
Views
Replies
Total Likes
var cToAddr = "Jim.Dandy@anywhere.com"
var cSubLine = "Property Accountability Form Submission"
function GetBody()
{
var body = "Non-Core Software Request Form" + "\n\n"
+ " **** User Information ****" + "\n";
if ( ! RequestorName.isNull )
body =+ "Requestor:\t\t\t" + RequestorName.formattedValue + "\n";
if ( ! Organization.isNull )
body =+ "Organization:\t\t\t" + Organization.formattedValue + "\n";
return body
}
cBody = GetBody()
if (form1.execValidate() == false)
{
xfa.host.messageBox("One of the required fields highlighted in red is missing. " + "\n"
+ "Please complete required field and attempt submission again.")
}
else
{
var oDoc = event.target;
oDoc.mailDoc({bUI: true,cTo: cToAddr,cSubject: cSubLine,cMsg: cBody});
}
Views
Replies
Total Likes
Just syntax issues, the main issue is you have =+ ( which is assignment) instead of += (which is concat). Correct one should be +=
Views
Replies
Total Likes
Things are Golden now, thank you very much!
Views
Replies
Total Likes
Views
Likes
Replies