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.

Email script is not working in the subject

Brijmohan
Tera Contributor

I am calling email script in Notification subject. It is not working in the subject and same script working in the body. PFB script that I am using in email script.

 

var str = current.short_description.toString();
                var str1 = str.slice(0,10);
                template.print(str1);
                //email.setSubject('Information request '+current.number+' '+str1);

email.setSubject is working in subject but in that case I need to create separate email script for each notification.

 

Thanks & regards,

Brijmohan  

8 REPLIES 8

Jaspal Singh
Mega Patron
Mega Patron

Hi Brijmohan,

 

Can you try adding the email.setSubject() just before you set the description in the mail script.

Hi @Jaspal Singh , Thanks for your response but I don't want to use email.setSubject() because If I will use it i need to create more then one email script. I am just want to call email script in subject so I can only restrict 60 char like below.

var str = current.short_description.toString();
                var str1 = str.slice(0,60);
                template.print(str1);

 but this code is not working it is giving in subject ${mail_script:script_name} without email subject. 

 

Hi @Brijmohan,

 

You need to use email.setSubject(); method to set/override the subject using email scripts. with out setSubject() will not be able to set subject in notifications.

 

Try this updated scripts:

var str = current.short_description.toString();
var str1 = str.slice(60);
// template.print(str1);
email.setSubject('Information request ' + current.number + ' - ' + str1);


If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers! 👍🏻
Thanks,
Sagar Pagar

The world works with ServiceNow

Hi @Brijmohan,

 

Have you looked into my comments? let me know if have any issues so far.


If my response helps to solve your issue. Kindly mark it as helpful/correct. It will be helpful for future readers! 👍🏻
Thanks,
Sagar Pagar

The world works with ServiceNow