Trying to update a field of closed incidents through a script

Sunny Joel
Giga Expert

wrote a script under "sysauto_script.list" to update "Configuration Item" of closed incidents.

Trying to test it for one incident before running a update for all.

var gr = new GlideRecord('task');
gr.addQuery('number','INC2142115');
gr.query();
while(gr.next()){
gr.cmdb_ci = 'Atlas';
gr.update();
}

the following error is seen in  work notes of the ticket.

Can someone please help to find the reason for the update not going through.

 

1 ACCEPTED SOLUTION

You should use sys_id or displayValue.

var gr = new GlideRecord('task'); // why are you referring to task table here instead of incident
gr.addQuery('number','INC2142115');
gr.query();
while(gr.next()){
gr.setDisplayValue('cmdb_ci', 'Atlas');

gr.setWorkflow(false);
gr.update();

}


Please mark my response as correct and helpful if it helped solved your question.
-Thanks

View solution in original post

7 REPLIES 7

Prateek kumar
Mega Sage

Try this:

var gr = new GlideRecord('task'); // why are you referring to task table here instead of incident
gr.addQuery('number','INC2142115');
gr.query();
while(gr.next()){
gr.cmdb_ci = 'Atlas';

gr.setWorkflow(false);
gr.update();

}


Please mark my response as correct and helpful if it helped solved your question.
-Thanks

Sunny Joel
Giga Expert

Thank you for your quick reply Prateek.

Same problem with incident and setWorkflow function.

I've tried on a different incident, the field just goes to empty.

You should use sys_id or displayValue.

var gr = new GlideRecord('task'); // why are you referring to task table here instead of incident
gr.addQuery('number','INC2142115');
gr.query();
while(gr.next()){
gr.setDisplayValue('cmdb_ci', 'Atlas');

gr.setWorkflow(false);
gr.update();

}


Please mark my response as correct and helpful if it helped solved your question.
-Thanks

Would you mind closing the thread by marking my response as correct.

This helps in removing the thread from unanswered list and helps community.

 

-Cheers

Prateek 


Please mark my response as correct and helpful if it helped solved your question.
-Thanks