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

Harsh Vardhan
Giga Patron

use new GlideDate(request.opened_at)

 

then try addDays(30);

Harsh Vardhan
Giga Patron

eg:

 


var gdt = new GlideDateTime("2011-08-31 08:00:00");


gdt.addDays(30);


gs.print(gdt);

Community Alums
Not applicable

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?

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