- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-15-2019 12:06 PM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-15-2019 12:19 PM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-15-2019 12:16 PM
cmdb_ci is a reference field so you need to provide the sys_id of the CI record you want to reference, not the string name.
var gr = new GlideRecord('task');
gr.addQuery('number','INC2142115');
gr.query();
while(gr.next()){
gr.cmdb_ci = 'cb103af8db6723002f153c8f9d9619af'; //<-- sys_id here
gr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-15-2019 12:19 PM
Perfect.
That went through.
Thank you very much guys.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-15-2019 12:19 PM
Since cmdb_ci is a reference field, you have to update like this.
Also, you need to update incident table, not task table.
var gr=new GlideRecord("incident");
gr.addQuery("number","INC2142115");
gr.query();
if(gr.next()) {
var gr1=new GlideRecord("cmdb_ci");
gr1.addQuery("name","Atlas");
gr1.setLimit(1);
gr1.query();
if(gr1.next()) {
gr.cmdb_ci=gr1.sys_id;
gr.update();
}
}
I tried in my dev instance nad it's working fine.
Mark the answer as correct once it worked.