Email Script - Hide Fields in Email Notification

WP2
Kilo Guru

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>&nbsp;</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.

1 ACCEPTED SOLUTION

puneetgoels1
Tera Guru

try this 

 

if (current.sysapproval.variables.description)

{

...

}

View solution in original post

9 REPLIES 9

joshuamayes
Giga Expert

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>&nbsp;</div>');
}

Thanks for your help.

I tried but same result in the notification (see below)

find_real_file.png

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>&nbsp;</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).  

SanjivMeher
Kilo Patron
Kilo Patron

Try this

 

if (current.sysapproval.variables.description.getDisplayValue()!='')

template.print('<div>Description: ' + (current.sysapproval.variables.description ? current.sysapproval.variables.description.getDisplayValue().toString() : "" )+ '</div><div>&nbsp;</div>');


Please mark this response as correct or helpful if it assisted you with your question.