applying a condition to a field in an email subject

scottjus82
Kilo Guru

Hi,

 

I am setting up a Calendar invite for change requests and an issue (amongst others) I have is adding a field to the email template subject if its populated with yes? the field asking if there is an outage and its a drop down with a Yes/No option. I want to add this field to the subject if there will be an outage so when its added to a calendar its clear that this change includes an outage. At the moment I am calling the field with the line "is there an outage" which then adds yes or no. What I really want is the word outage to show if there is one and nothing to show if there isnt.

 

Any thoughts?

 

Regards

1 ACCEPTED SOLUTION

I'm guessing that they don't work from meeting invites. In that case you'll probably need to go with 2 different notifications where one has your outage subject and the other does not, then use the notification conditions to determine which should fire.


View solution in original post

8 REPLIES 8

Brad Tilton
ServiceNow Employee
ServiceNow Employee

You'd have to do this with some javascript in a mail script that takes a look at your conditions and then sets the subject of the email. You can use email.setSubject() from a mail script to change the subject line.



Scripting for Email Notifications - ServiceNow Wiki


Hey,



Thanks, that would certainly seem to be the method to use. Any thoughts on what the script would look like? i have tried a couple of varients using an if statement to check that the ooutage questions is true and then set the subject but my mail script is being ignored.



Thanks


Hi Steve,



Assuming that your notification is being sent out from change request and your outage field is called u_outage and is a checkbox (true/false) field, it would look something like this:



<mail_script>


if (current.u_outage == true) {


  email.setSubject('This is an outage');


}


</mail_script>



If that doesn't work, I would check the field name and type and then make sure the email is being sent from the change_request table itself.


Hi Brad,



Thanks very much for your help so far. I still cant get it working. your


script makes sense to me. I have amended the U_outage to reflect the one on


our instance. the field is actually a string with choices. I have changed


the true to a Yes both with '' and without but its still not working.



Thanks




On 13 August 2014 14:21, Brad Tilton <community-no-reply@servicenow.com>