- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2023 09:08 PM
I want to print a variable value in approval notification script, only when the variable exists in the corresponding RITM.
The name of the catalog variable is city, the variable type is single-line text (i.e. String).
Below is my code:
var v_city = "${sysapproval.variables.city}";
if(v_city)
template.print("City: ${sysapproval.variables.city}");
If user has entered 'New York' in the catalog field, the above prints: City: New York --- which is perfectly ok.
But if the city variable was hidden (not displayed through some UI policy) in the catalog, then the above prints:
City: --- blank value is shown here
What I really want is not to print anything when that variable was hidden in the catalog from the user.
Can somebody please tell what I am doing wrong here.
Thanks.
Please mark this post as a solution and also as helpful, if this resolves your issue or query.
Thanks,
Subhadeep Ghosh.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2023 12:22 AM
Checked by putting logs, if variable value is empty then gs.log(${sysapproval.variables.city}) returning some value, not sure what but I think it may be # code or something.
Below code worked for me...!!
var v_city = current.sysapproval.variables.city;
if(v_city == '') {
template.print("");
} else {
template.print("City: ${sysapproval.variables.city}");
}
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2023 12:22 AM
Checked by putting logs, if variable value is empty then gs.log(${sysapproval.variables.city}) returning some value, not sure what but I think it may be # code or something.
Below code worked for me...!!
var v_city = current.sysapproval.variables.city;
if(v_city == '') {
template.print("");
} else {
template.print("City: ${sysapproval.variables.city}");
}
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2023 12:58 AM
Hi @Vishal Birajdar ,
Lots of thanks for taking your time and helping me out here.
Your solution has finally worked.
This was so simple, yet so hard to find.
Hope we interact more in the future.
Thanks,
Subhadeep.
Please mark this post as a solution and also as helpful, if this resolves your issue or query.
Thanks,
Subhadeep Ghosh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2023 01:03 AM
Definitely...!!! we can...!!
Happy to help..!
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2023 11:49 PM - edited 10-19-2023 11:50 PM
Hi @subhadeep1618 You can create a email script and call the email script in Notification.
Email Script:
if(current.sysapproval.variables.city){
template.print('city:' + current.sysapproval.variables.city+ '<br/>');
}
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2023 11:59 PM
Hi @subhadeep1618 ,
Convert into string and trim whitespaces if any use below script.
if (current.sysapproval.variables.city) {
var cityValue = current.sysapproval.variables.city.toString().trim();
if (cityValue !== '') {
template.print("City: " + cityValue);
}
}
Thanks,
Anand