How to check if a RITM variable has value in approval notification email script?

subhadeep1618
Tera Guru

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.
1 ACCEPTED SOLUTION

Hi @subhadeep1618 

 

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

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

View solution in original post

10 REPLIES 10

Dipen Wadhwana
Giga Guru

Hi @subhadeep1618 ,

 

Can you please try the below  script :

var v_city = current.sysapproval.variables.city;
if(v_city){
	template.print("City: "+v_city);
}

 

When you were using var v_city = "${sysapproval.variables.city}"; the value was undefined which was getting stored.

 

Please let me know if this works for you and mark helpful if its worked.

 

Thanks,

Dipen