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

Hi,

I have tried above script and changed to before insert and update.

then I got this message : time after adding date: undefined

Regards,

Sowmya

ah my bad. missed on line

 

var gdt = new GlideDateTime(current.u_time_when_the_resolved_notif); 

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

current.u_mi_action_due_date = gdt.getLocalDate();  // if its date time type field use gdt.getDisplayValue()

find_real_file.png

But I have received message like this

 "time after adding date: 2020-07-25 16:40:53"

But it's not adding the date to "due date" field

 

Thanks,

Sowmya

 

just confirming , have you used below line ? if its coming in info message then it should also set the same value. i am assuming you are not using current.update() in your business rule.

 

current.u_mi_action_due_date = gdt.getDisplayValue();  
 

Hi,

I have removed current.update() line. 

And one more thing is that "MI action due date" is on Incident task table.

How to display that date to "MI action due date" for incident task.

 Both the field type is "glide_date_time".