- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2019 09:59 AM
Hello All,
I have the below email script however, i will like to hide these fields (e.g Description etc) in the email notification when no value is provided. In the email notification, they should be hidden only when no value is provided. What is the logic to achieve this for the below scripts?
1. template.print('<div>Description: ' + (current.sysapproval.variables.description ? current.sysapproval.variables.description.getDisplayValue().toString() : "" )+ '</div><div> </div>');
2. template.print("Summary:\n");
var gr = new GlideRecord("sc_req_item");
gr.addQuery("request", current.sysapproval);
gr.query();
while(gr.next()) {
template.print(gr.number + ": " + gr.quantity + " X " + gr.cat_item.getDisplayValue() + " at " + gr.cat_item.price.getDisplayValue() + " each \n");
}
3. Comments: ${sysapproval.comments}
Thank you.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2019 11:50 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2019 10:33 AM
I'm not very experienced in mail-scripts in particular, but have you tried using an if statement to check if the value exists?
I'm not quite sure what your script is doing so forgive me if I butchered it.. but I imagine your answer looking something like this:
if(current.sysapproval.variables.description.toString() != ''){
template.print('<div>Description: ' + (current.sysapproval.variables.description ? current.sysapproval.variables.description.getDisplayValue().toString() : "" )+ '</div><div> </div>');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2019 11:09 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2019 01:04 PM
Ah okay, so what I think is going on here is that your template.print() function isn't working properly.
Try this:
if(current.sysapproval.variables.description.toString() != ''){
template.print('<div>Description: ' + current.sysapproval.variables.description.toString() + '</div><div> </div>');
}
Otherwise it might be that even though the description is blank the if statement is evaluating to true. Likely because the variable is returning NULL which isn't equal to an empty string. In that case replace the condition for the if statement with if(current.sysapproval.variables.description).

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2019 10:40 AM
Try this
if (current.sysapproval.variables.description.getDisplayValue()!='')
template.print('<div>Description: ' + (current.sysapproval.variables.description ? current.sysapproval.variables.description.getDisplayValue().toString() : "" )+ '</div><div> </div>');
Please mark this response as correct or helpful if it assisted you with your question.