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

Thank you for your help.

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

find_real_file.png

//try adding a trim()

 

f (current.sysapproval.variables.description.getDisplayValue().trim()!='')
{
	template.print('<div>Description: ' + (current.sysapproval.variables.description ? current.sysapproval.variables.description.getDisplayValue().toString() : "" )+ '</div><div>&nbsp;</div>');
}
Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022

puneetgoels1
Tera Guru

try this 

 

if (current.sysapproval.variables.description)

{

...

}

Thank you, Puneet.

This worked like magic for number 1. I tried to apply the same logic for 2&3 but no luck. Number 2 is a <mail_script></mail_script> in Email Template. How can I apply the same logic to work in email template for 2&3?

I guess it should work in similar way

 

if (current.sysapproval)

{

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

}

 

if (${sysapproval.comments})

{

${sysapproval.comments}

}