- 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:04 PM
use new GlideDate(request.opened_at)
then try addDays(30);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2020 11:06 PM
eg:
var gdt = new GlideDateTime("2011-08-31 08:00:00");
gdt.addDays(30);
gs.print(gdt);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2020 11:19 PM
Hi harsh,
The exact code which you posted it s working. But if i paste my code, it is giving undefine only.
var request = new GlideRecord('sc_req_item');
request.get('a75c29f9dbdd1050dbf414a05b961915');
var date1 = new GlideDateTime(request.opened_at);
var date2 = date1.addDays(30);
gs.print('Date 1 is ' + date1);
gs.print('Date 2 is ' + date2);
Can you please try in your instance by putting some other sys_id?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2020 11:24 PM
try now
var request = new GlideRecord('sc_req_item');
request.get('a75c29f9dbdd1050dbf414a05b961915');
var date1 = new GlideDateTime(request.opened_at);
date1.addDays(30);
gs.print('Date 1 is ' + date1);