How to populate incident configuration item field in a transform map

jonny1
Giga Contributor

My script successfully creates an incident, but I'd like the configuration item of each incident to be the 'ServiceNow' application. This is what I have:

var grInc = new GlideRecord('incident');

grInc.initialize();

grInc.cmdb_ci = 'ServiceNow';

grInc.short_description = '...';

grInc.work_notes = '...' ;

grInc.insert();

The incident contains the description and notes, but the CI field is blank. I assume I should be assigning it to something other than a string, but after thorough searching I can't find how to do it.

Thanks in advanced.

1 ACCEPTED SOLUTION

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hi Jonny,



Since the configuration item field is a reference it's expecting a sys_id when you set it that way. I would try this line instead:



grInc.cmdb_ci.setDisplayValue('ServiceNow');



That way you can pass it the display value of the record as a string.


View solution in original post

4 REPLIES 4

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hi Jonny,



Since the configuration item field is a reference it's expecting a sys_id when you set it that way. I would try this line instead:



grInc.cmdb_ci.setDisplayValue('ServiceNow');



That way you can pass it the display value of the record as a string.


i updated the same but instead of updating the cmdb ci , it created a new incident and updated the cmdb ci there.

 

 

 

this is my table transform script 

 

(function transformRow(source, target, map, log, isUpdate) {

var grInc = new GlideRecord('incident');

grInc.initialize();

// grInc.cmdb_ci.setDisplayValue('ServiceNow');

grInc.contact_type = "System Generated";
grInc.u_caller.setDisplayValue("25baf8a6dbd6a810d7649254db961974");
grInc.caller_id.setDisplayValue("25baf8a6dbd6a810d7649254db961974");
grInc.opened_by.setDisplayValue("25baf8a6dbd6a810d7649254db961974");
grInc.u_verb = "Alert";


grInc.update();
})(source, target, map, log, action==="update");

jonny1
Giga Contributor

Worked like a charm, thanks Brad!!


Brad Tilton
ServiceNow Employee
ServiceNow Employee

No problem, and this wiki article is a great reference for GlideRecord methods:



http://wiki.servicenow.com/?title=GlideRecord#gsc.tab=0