Date calculation - Add 30 days.

Community Alums
Not applicable

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.?

find_real_file.png

Output of BG

find_real_file.png

 

Regards,

Sirraj

1 ACCEPTED SOLUTION

kamer
Kilo Expert

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);

View solution in original post

11 REPLIES 11

dont store into variable. simply use the same variable 

 

future reference refer the doc link

 

https://developer.servicenow.com/dev.do#!/reference/api/orlando/server_legacy/c_GlideDateTimeAPI#r_G...

Community Alums
Not applicable

Thanks Harsh 🙂

kamer
Kilo Expert

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);

Community Alums
Not applicable

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

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.

https://community.servicenow.com/community?id=community_article&sys_id=4c66ff4a1bde08107a5933f2cd4bc...

Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.

Regards,
Asif
2020 ServiceNow Community MVP