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

yes you can use in mail script. go with GlideSchedule method .

 

var startDate = new GlideDateTime('start date');

var days = 10;

var dur = new GlideDuration(60 * 60 * 24 * 1000 * days); // your duration goes here

var schedule = new GlideSchedule('sys_id of your weekday schedule');

var end = schedule.add(startDate, dur);

 

if my answer helped you, kindly mark it as correct and helpful.

 

Tejas Tamboli
Giga Guru

Hello Sirraj,

You can try below script:

//Put your sys_id in the script

find_real_file.png

 

find_real_file.png

 

 

I hope this will help you.

 

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response useful to you and help others to find information faster.

 

Thanks,

Tejas