Set the subject with a mail script on an email notification

stevewilson
Kilo Contributor

What I am trying to do is set the subject of an email notification. There is a field in the subject that needs to be shortened via a script and then added.

I have created a Notification Email Script and have tried using template.print and email.setSubject to add my shortened field. I have tried putting the script in the subject field and also in the body of the message.

The email subject looks something like this:

RMA For: ${field1}-${field2}-${mail_script:shortenedEmailField}-${parent.location}

But when its being sent out I can still see the ${mail_script:shortenedEmailField} part in the subject.

Unfortunately the wiki is out of date again and is still referring to the older method of adding scripts to mail. <mail_script> email.setSubject('Email Subject'); </mail_script>

3 REPLIES 3

Julian Hoch
ServiceNow Employee
ServiceNow Employee

You can create a mailscript that you call in the body where you set the subject with:


email.subject = "MY NEW SUBJECT"



See also: Setting email subject with a mail script


Aanchal Mehndi1
Giga Contributor

Hi Steve,



I believe, you cannot call mail script into a subject.


You have to call mail script in a body to set subject through script.


Raju Koyagura
Tera Guru

In the email script use this code to set the subject


email.setSubject("Your Subject").