Add Date to Subject Line for Notifications
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2019 09:02 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2019 10:46 AM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2019 09:28 AM
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
Abhishek Gardade