add day to a date field

Sowmya20
Tera Contributor

I have two field "MI service restore(u_time_when_the_resolved_notif) and MI action due date(u_mi_action_due_date). I want to add 7 days to MI service restore and display in MI action due date.

I have written Business rule for this but it's not  displaying the date.

Here is my code:

var gdt = new GlideDateTime(current.u_time_when_the_resolved_notif); 

var aft= gdt.addDays(7);
gs.addInfoMessage("time after adding date: "+ aft);

current.u_mi_action_due_date = gdt.getDate();

current.update();

 

Can anyone help me on this.

Regards,

Sowmya

1 ACCEPTED SOLUTION

ok then you have to do glide record here to update the column on incident task table. 

 

eg:

 

var gdt = new GlideDateTime(current.u_time_when_the_resolved_notif);

gdt.addDaysLocalTime(7);
gs.addInfoMessage("time after adding date: "+ gdt.getDisplayValue());

var gr = new GlideRecord('incident_task');

gr.addQuery('incident',current.sys_id); // make sure the relationship field is parent or incident.

gr.query();

while(gr.next()){

gr.<your date field on incident task > = gdt.getDisplayValue();

gr.update();

}

 

View solution in original post

22 REPLIES 22

Ashutosh Munot1
Kilo Patron
Kilo Patron

Hi,

I dont know if you try this:

var gdt = new GlideDateTime(current.u_time_when_the_resolved_notif); 

gdt.addDays(7);
current.u_mi_action_due_date = gdt.getDate();

current.update();

ASSUMING u_mi_action_due_date  is a date field,


Thanks,
Ashutosh

Hi,

I have tried above script. But still not displaying.

Both the fields are glide_date_time type.

 

Thanks,

Sowmya

HI,

If they are glide date time then use this:

var gdt = new GlideDateTime(current.u_time_when_the_resolved_notif); 

gdt.addDays(7);
current.u_mi_action_due_date = gdt.getDisplayValue();

current.update();


Thanks,
Ashutosh

Try this?


Thanks,
Ashutosh

Harsh Vardhan
Giga Patron

Make sure business rule is before business rule. also avoid using current.update().

Avoid addDays() and use either addDaysLocalTime() or addDaysUTC()

 

your updated script:

 

var gdt = new GlideDateTime(current.u_time_when_the_resolved_notif); 

gdt.addDaysLocalTime(7);
gs.addInfoMessage("time after adding date: "+ gdt.addDaysLocalTime(7));

current.u_mi_action_due_date = gdt.getLocalDate();

 

Doc link for further details. 

 

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