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.

Add info to subject with Email Script in Email Client Template (email action on a Change record)

Dorian MOREL
Tera Contributor

Hello there,

 

I am trying to run an email script to add the current month to the subject, but it won't work.

 

DorianMOREL_0-1764341225408.png

Any idea why ?
I'm calling my email script in the HTML field of the Email Client Template. It should be running when a user wants to send an Email with the email feature on a Change record.

 

If it is impossible with this method, is there any workaround to achieve what I want to do ? 

 

Thank you in advance.
Dorian

 

2 REPLIES 2

Anand2799
Tera Guru

Hi @Dorian MOREL ,

 

Try this:

    var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];

    var gdt = new GlideDateTime(); //November
    var current_month = gdt.getMonth(); // returns number

    email
.setSubject("Test Subject : " + months[current_month - 1]);


Thanks

Anand

Sheldon  Swift
ServiceNow Employee
ServiceNow Employee

Hi @Dorian MOREL - You would get the current email subject with email.getSubject() With your code, something like this should work:

 var months = ["JANVIER", "FEVRIER", "MARS", "AVRIL", "MAI", "JUIN", "JUILLET", "AOUT", "SEPTEMBRE",
     "OCTOBRE", "NOVEMBRE", "DECEMBRE"
 ];
 var nb_month = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"];

 var gdt = new GlideDateTime();
 var month = gdt.getMonth().toString();

email.setSubject(email.getSubject() + " " + months[nb_month.indexOf(month)].toString());

Keep in mind that you can get the current month name from GlideDate if you want to skip the mapping:

var date = new GlideDate();
var month = date.getByFormat("MMMM");