- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2020 10:57 PM
Hi All,
I am sending a notification to the approver once the request is submitted. Body of the notification will be
Kindly approve the request which created on "Date 1" by "Abel Tuter". You have to approve/decline the request before "Date 1 +30".
I have written a mail script to print the date1, how can i add 30 days and display the date2 in notification.
Please find the email script below for date1 :
var request = new GlideRecord('sc_req_item');
request.get(event.parm1); //parm1 sys_id of ritm
template.print(request.opened_at);
I just tried the above in background script by addDays(30), am getting undefined. What mistake i am doing here.?
Output of BG
Regards,
Sirraj
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2020 11:06 PM
hello ,
Try below code for adding days:
var gdt = new GlideDateTime();
gdt.addDaysLocalTime(30);
current.datefield = gdt;
Note:addDays() is a deprecated method so try using addDaysLocalTime().
else try like this in Background script:
var nd = new GlideDateTime(gs.nowDateTime());
gs.print('current date is :'+nd);
var fd = new GlideDateTime(nd);
fd.addDays(30);
gs.print('future date will be:'+fd);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2020 11:25 PM
dont store into variable. simply use the same variable
future reference refer the doc link
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2020 11:39 PM
Thanks Harsh 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2020 11:06 PM
hello ,
Try below code for adding days:
var gdt = new GlideDateTime();
gdt.addDaysLocalTime(30);
current.datefield = gdt;
Note:addDays() is a deprecated method so try using addDaysLocalTime().
else try like this in Background script:
var nd = new GlideDateTime(gs.nowDateTime());
gs.print('current date is :'+nd);
var fd = new GlideDateTime(nd);
fd.addDays(30);
gs.print('future date will be:'+fd);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2020 11:35 PM
Thank you kamar. It worked, the second part of your script.! One final question, i need to add 30 days but also if i want to exclude holidays means? Can that also be acheivable in mail script?
Regards,
Sirraj

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2020 11:40 PM
Hello Sirraj,
For that you need to use schedules. Create a schedule and check.
Refer to my article where i have shown example on how to use schedule.
Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.
Regards,
Asif
2020 ServiceNow Community MVP