Add Date to Subject Line for Notifications

DP16
Kilo Expert

How can I add a date to my subject line. 

So, that means, every time this particular notification goes out, it will at least have the date. 

This is what I have configured so far. 

find_real_file.png

6 REPLIES 6

In an email script, you'd want to add the following:

var gdt = new GlideDateTime(current.sys_updated_on);

email.setSubject("Position Role 3 Report " + gdt.getDate());

Then in the body of your notification you'd want to call the Mail script

${mail_script:scriptName}

 

If you really want to get the MM-DD-YYYY format you can do something like this in the email script:

var gdt = new GlideDateTime(current.sys_updated_on);

email.setSubject("Position Role 3 Report " + gdt.getMonthLocalTime() + "-" + gdt.getDayOfMonthLocalTime() + "-" + gdt.getYearLocalTime());

There may be an easier way, but that's the way I thought of without research.

Hope this helps!

AbhishekGardade
Giga Sage

Hello DP, 

Its simple:

you can set subject from email script instead of setting it direct.

To dynamically change field values within an email, use the following functions within <mail_script> syntax:

1. create mailscript and add below code:

name: setsubject

var date =  gs.nowDateTime() ; // use value you want email
.setSubject("Position Role 3 Report"+date);

Reference:
https://docs.servicenow.com/bundle/newyork-servicenow-platform/page/script/server-scripting/referenc...

 

2. you need to call this from notification body as below:

${mail_script:setsubject}

Please mark as Correct Answer and Helpful, if applicable.
Thanks!
Abhishek Gardade
Hexaware Technologies

Thank you,
Abhishek Gardade