- 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-19-2023 09:32 PM
Hi @subhadeep1618 ,
You can just put the condition like below. instead of only if(v_city)
if(v_city != ''){
template.print("City: ${sysapproval.variables.city}")
}
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2023 09:50 PM
Hi @Danish Bhairag2 ,
That's the very first thing I did, but it did not work - same issue I was getting.
Then I changed to if(v_city), but this is also not working.
Thanks.
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-19-2023 11:11 PM
Can you try like this...!!!
It's the same logic you have tried earlier...Just a little adjustment...
var v_city = "${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-19-2023 11:31 PM
Hi @Vishal Birajdar ,
I've tried your suggestion, but now it is always going inside the else block.
So its the same issue.
Can you please check if there is a definite way to check NULL or Undefined value of variable?
I am also checking.
Thanks.
Please mark this post as a solution and also as helpful, if this resolves your issue or query.
Thanks,
Subhadeep Ghosh.