Email Script (To print dynamic days through Email notification)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2025 10:16 PM
Hi,
I have created a below script however when I am triggering notification it is showing days like that in format 14141415. Could you please let me know what is the specific issue because of which it is showing like this.
Name of the email script :- sn_dynamic_values_renewal_date
Below is the attached code for reference: -
Eg :- Renewal date is scheduled on 09/07/2026
and the TEST Record is created on 09/07/2025 14:03:00
Based on the given script it is showing result as 0206101012 days as
This is to inform you that the TEST is scheduled for renewal on 09/07/2026, which is 0206101012 days from today.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2025 11:08 PM
We are not sure how you are triggering the email.
I believe you are using some scheduled job, if that's the case then you should get details only for that record and print the details.
Please share some more details about your requirement, screenshots of what you configured etc
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2025 11:16 PM
Yes, I am triggering through the scheduled job but multiple records are meeting the criteria and in the notification, it is showing as 10101012 something like that. I would like to show specific days for a particular day. Like I have created Test which is 45 days renewal date based on current date
And Another record Test1 which is 15 days renewal date based on current date then when I will execute schedule job then it show 45 days for Test and 15 days Test1 due for renewal in notification. I hope you are able to understand otherwise I will elaborate more on this. pls let me know.
I have added the Scheduled Job for your reference
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var user;
var gr = new GlideRecord('sn_compliance_policy');
gr.addQuery("state", "draft");
gr.query();
while (gr.next()) {
var u = new GlideDateTime(gr.u_next_renewal_date);
var c = new GlideDateTime().getDate();
var d = gs.dateDiff(c, u, true);
var days = d / (60 * 60 * 24);
// var days = parseInt(d,10)/(60*60*24);
if (days == 15 || days == 14 ||days == 12 ||days == 10 ||days == 8 || days == 6 ||days == 4 ||days == 2||days == 0) {
// template.print("u_next_renewal_date" + days + " days<br/>");
template.print(days);
}
// Add your code here
}
})(current, template, email, email_action, event);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2025 11:28 PM
then use current object in the email script I shared above.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2025 11:32 PM
could you pls let me know where to add current and the code shared by you will trigger if days matches with 15 , 14 , 13 , 12 , 11. so on or it will trigger only specific record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2025 01:59 AM
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader