Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Struggle with 'if' statement in email script

curtisr
Kilo Expert

Hi everyone, I need a bit of help. I am trying to modify an email script that is called from an Incident Alert notification that checks to see if the value of a checkbox is true or false. I am able to template.print the true value to the resulting email, but I cannot for the life of me get an if statement to work so it only prints the value if it is true.

I have a variable on the IA form called u_ialerts_globaloutage. The line below prints out true or false depending on the variable.

template.print ("<br>Global Outage:"+current.u_ialerts_globaloutage+"</br>");

I would assume that the snippit below would only print out if the value is true as the value is confirmed in the line above.

if (current.u_ialerts_globaloutage == 'true'){

  template.print("This is a Global Outage");

}

But, i don't get any output from this line on the email that is sent (everything else before and after this is present as expected). I have to be missing something, but after 3 hours of looking over the community & wiki without result I am at a loss.

Thank you in advance

Curtis

1 ACCEPTED SOLUTION

wonkaba
Mega Contributor

Haven't worked with email scripts so this might not apply but if u_ialerts_globaloutage is a boolean value, do you need the single quotes around the value in the if statement?



Should it be:


if (current.u_ialerts_globaloutage == true){...



OR



Couldn't you simplify it to:


if (current.u_ialerts_globaloutage){...


View solution in original post

3 REPLIES 3

wonkaba
Mega Contributor

Haven't worked with email scripts so this might not apply but if u_ialerts_globaloutage is a boolean value, do you need the single quotes around the value in the if statement?



Should it be:


if (current.u_ialerts_globaloutage == true){...



OR



Couldn't you simplify it to:


if (current.u_ialerts_globaloutage){...


kristenankeny
Tera Guru

You may need to use current.getDisplayValue('u_ialerts_globaloutage) == 'true'


curtisr
Kilo Expert

Thank you Archie & Kristen! Both of your options worked and accomplished what i was looking for. I am going to mark Archies is correct as it is a slightly cleaner approach, but will also mark Kristens as helpful.



My only regret is not asking earlier . You folks rock.