gr.update() not updating date field in a record in background script.

Community Alums
Not applicable

Hi All,

I am trying to update a date/time field in a record using background script.

I am able to get the required time and everything but the field is not getting updated with the new time in the record. I have used gr.update() and gr.setForceUpdate() but the field shows the old value.

I am using the below script:

var gr= new GlideRecord('incident');
gr.addQuery('number','INC071439');
gr.query();
if(gr.next());{
gs.print('callback date is' + " " + gr.u_callback_date);
var actual_time= gr.u_callback_date.getDisplayValue();
var gdt = new GlideDateTime();
gdt.setValue( gr.u_callback_date.getDisplayValue());
gdt.addSeconds(05);
var new_time=gdt.getValue();
gs.log('new time is: '+new_time);
gs.log('Actual time is: '+ actual_time);

gr.update();
}

The logs come up fine but the field data remains the same in the record. Please assist me in this regard.

Thank you

 

1 ACCEPTED SOLUTION

User166992
Tera Guru

Hello Vishnu,

 

Try this:

var gr= new GlideRecord('incident');
gr.addQuery('number','INC071439');
gr.query();
if(gr.next());{
gs.print('callback date is' + " " + gr.u_callback_date);
var actual_time= gr.u_callback_date.getDisplayValue();
var gdt = new GlideDateTime();
gdt.setValue( gr.u_callback_date.getDisplayValue());
gdt.addSeconds(05);
var new_time=gdt.getValue();
gs.log('new time is: '+new_time);
gs.log('Actual time is: '+ actual_time);

gr.setValue('u_callback_date', new_time);

gr.update();
}

View solution in original post

3 REPLIES 3

User166992
Tera Guru

Hello Vishnu,

 

Try this:

var gr= new GlideRecord('incident');
gr.addQuery('number','INC071439');
gr.query();
if(gr.next());{
gs.print('callback date is' + " " + gr.u_callback_date);
var actual_time= gr.u_callback_date.getDisplayValue();
var gdt = new GlideDateTime();
gdt.setValue( gr.u_callback_date.getDisplayValue());
gdt.addSeconds(05);
var new_time=gdt.getValue();
gs.log('new time is: '+new_time);
gs.log('Actual time is: '+ actual_time);

gr.setValue('u_callback_date', new_time);

gr.update();
}

Melisa Urbano
Tera Contributor

Hi! Did you ever find a solution to this ?

Hello,

I think Vishnu was able to use my script. can you please have a look and let me know if that works for you.