- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2021 11:29 AM
We have the below Email Notification that was created to send out to key people during a Change Request. I need help to determine how to hide the additional variable details if blank.
In the below, if during the raise of the Change Request Group 2 and/or Group 3 is not required. The fields on the Request are left blank. So we would want to then hide the below sections so that the email notification is clean.
Is this possible? And how?
Email Notification as written (HTML):
- ${u_reference_3} //Group 1 Name
- ${u_reference_4} //Group 2 Name
- ${u_reference_5} //Group 3 Name
Email Notification:
- ${u_reference_3} //Group 1 Name
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2021 12:23 PM
You will want to use Mail Scripts to do this: https://docs.servicenow.com/bundle/quebec-servicenow-platform/page/script/server-scripting/concept/c...
Basically, write if statements to determine if the fields are empty or not. If they are not empty, use template.print() to output the info to the notification body. In the notification body, you reference the mail script like this: ${mail_script:[nameofmailscript]}
if (current.getValue('u_reference_3') != '') {
template.print('Start: ' + current.u_glide_date_time_2 + '<br />');
template.print('<ul><li>' + current.u_reference_3.getDisplayValue() + '</li></ul>');
}
if (current.getValue('u_reference_4') != '') {
template.print('Start: ' + current.u_glide_date_time_3 + '<br />');
template.print('<ul><li>' + current.u_reference_4.getDisplayValue() + '</li></ul>');
}
if (current.getValue('u_reference_5') != '') {
template.print('Start: ' + current.u_glide_date_time_4 + '<br />');
template.print('<ul><li>' + current.u_reference_5.getDisplayValue() + '</li></ul>');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2021 12:23 PM
You will want to use Mail Scripts to do this: https://docs.servicenow.com/bundle/quebec-servicenow-platform/page/script/server-scripting/concept/c...
Basically, write if statements to determine if the fields are empty or not. If they are not empty, use template.print() to output the info to the notification body. In the notification body, you reference the mail script like this: ${mail_script:[nameofmailscript]}
if (current.getValue('u_reference_3') != '') {
template.print('Start: ' + current.u_glide_date_time_2 + '<br />');
template.print('<ul><li>' + current.u_reference_3.getDisplayValue() + '</li></ul>');
}
if (current.getValue('u_reference_4') != '') {
template.print('Start: ' + current.u_glide_date_time_3 + '<br />');
template.print('<ul><li>' + current.u_reference_4.getDisplayValue() + '</li></ul>');
}
if (current.getValue('u_reference_5') != '') {
template.print('Start: ' + current.u_glide_date_time_4 + '<br />');
template.print('<ul><li>' + current.u_reference_5.getDisplayValue() + '</li></ul>');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2021 12:41 PM
Tim,
sorry for the delay. Thank you for this help. Could you help with the basic If statement to determine if empty or not? I am not the greatest on scripting.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2021 12:47 PM
Tim,
sorry. never mind. Solved my own issue.