Help with hiding details on a notification if the variable is blank

Tony Landowski
Kilo Contributor

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):

ATTENTION :: Application Owners
 
This weekend IT will be applying this month's system security patches.
 
The following server group is scheduled to patch on:
 
Start : ${u_glide_date_time_2} //Group 1 Time
  • ${u_reference_3} //Group 1 Name
Start : ${u_glide_date_time_3} //Group 2 Time
  • ${u_reference_4} //Group 2 Name
Start : ${u_glide_date_time_4} //Group 3 Time
  • ${u_reference_5} //Group 3 Name
 
Depending on the schedule, we expect most servers to be finished by ${work_end}. Take note that this is not a full outage, rather periodic unavailability of software due to patching and reboots. 
 
For a detailed list of servers, view the sheet here and select the tab for the appropriate schedule.
 
We do not anticipate any issues following this outage; however, if you experience problems, please contact the Help Desk.

Thank you,
 
 
 
**Here is how we expect the notification to look if the additional sections are left blank:

Email Notification:

 

ATTENTION :: Application Owners
 
This weekend IT will be applying this month's system security patches.
 
The following server group is scheduled to patch on:
 
Start : ${u_glide_date_time_2} //Group 1 Time
  • ${u_reference_3} //Group 1 Name
 
Depending on the schedule, we expect most servers to be finished by ${work_end}. Take note that this is not a full outage, rather periodic unavailability of software due to patching and reboots. 
 
For a detailed list of servers, view the sheet here and select the tab for the appropriate schedule.
 
We do not anticipate any issues following this outage; however, if you experience problems, please contact the Help Desk.

Thank you,
1 ACCEPTED SOLUTION

Tim Deniston
Mega Sage
Mega Sage

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

View solution in original post

3 REPLIES 3

Tim Deniston
Mega Sage
Mega Sage

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

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.  

Tim,

sorry.  never mind.  Solved my own issue.