- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2020 12:07 PM
On our Case table, we have a UI Action called 'Create Incident'. I would like to update the script so it passes the values in the 'Service' field (u_service) and 'Assignment Group field (assignment_group) on the Case to the newly created Incident.
Here's the script currently. How would I add the additional values?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2020 12:38 PM
Use below code to update these custom fields.
createIncidentFromCase: function(caseGr, uiActionHandler) {
var incGr = new GlideRecord("incident");
var ep = new GlideScriptedExtensionPoint().getExtensions(ServiceManagementIntegrationConstants.CASE_INC_EXTENSION_POINT);
//If there is any other new extension instance other than the OOB one, concat them together
//The extension instance with higher order number would overwrite the one with lower order number
for(var i = 0; i < ep.length; i ++){
var point = ep[i];
point.copyFieldsFromCaseToIncident(incGr, caseGr);
}
var incSysId = incGr.insert();
var inc = new GlideRecord('incident');
inc.addQuery('sys_id',incSysId);
inc.query();
while(inc.next()){
inc.cmdb_ci = current.u_service;
inc.assignment_group = current.assignment_group;
inc.update();
}
caseGr.incident = incSysId;
caseGr.update();
gs.addInfoMessage(gs.getMessage("Incident {0} created", incGr.number));
uiActionHandler.openGlideRecord(incGr);
uiActionHandler.setReturnURL(caseGr);
},
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2020 01:50 PM
OK. Haven't really dealt with script includes. So, want to make sure I got this straight.
1. Create new script include. Will need to create a new name. Maybe similar to the current one. For example: ServiceManagementIncidentUtils_2
2. Copy OOB code and include the new lines you've provided.
3. Go to the 'Create Incident' UI Action and reference this new script include (ServiceManagementIncidentUtils_2).

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2020 02:04 PM
Yes, you are on right path.
Make sure that your script include is in same scope like your UI action to avoid in scope issues.
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2020 04:49 PM
OK. Got further. I was able to create an Incident from the Case, and it passed the Assignment Group to the Incident. However, it didn't pass the Service (u_service) from the Case to the Incident's Configuration Item (cmdb_ci) field. Below is the dictionary information for both fields, and the CreateIncidentfrom Case snippet configured in the script include.
On Incident form:
On Case form:
createIncidentFromCase: function(caseGr, uiActionHandler) {
var incGr = new GlideRecord("incident");
var ep = new GlideScriptedExtensionPoint().getExtensions(ServiceManagementIntegrationConstants.CASE_INC_EXTENSION_POINT);
//If there is any other new extension instance other than the OOB one, concat them together
//The extension instance with higher order number would overwrite the one with lower order number
for(var i = 0; i < ep.length; i ++){
var point = ep[i];
point.copyFieldsFromCaseToIncident(incGr, caseGr);
}
var incSysId = incGr.insert();
var inc = new GlideRecord('incident');
inc.addQuery('sys_id',incSysId);
inc.query();
while(inc.next()){
inc.cmdb_ci = current.u_service;
inc.assignment_group = current.assignment_group;
inc.update();
}
caseGr.incident = incSysId;
caseGr.update();
gs.addInfoMessage(gs.getMessage("Incident {0} created", incGr.number));
uiActionHandler.openGlideRecord(incGr);
uiActionHandler.setReturnURL(caseGr);
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2020 04:53 PM
The Service field on the Case is a Choice field (with 20 choices). The Configuration Item field on the Incident is a reference field pointing to the Configuration Item table. Should I change the Configuration Item field to a choice field, and add the same 20 choices I have on the Service field on the Case?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2020 05:00 PM
Use below code
But, you need to make sure that choice list value is matching CI name in cmdb_ci table for this code to work.
Ideally, you should change data type of u_service field to Reference and point to cmdb_ci table.IF you do that, then your current code will work.
createIncidentFromCase: function(caseGr, uiActionHandler) {
var incGr = new GlideRecord("incident");
var ep = new GlideScriptedExtensionPoint().getExtensions(ServiceManagementIntegrationConstants.CASE_INC_EXTENSION_POINT);
//If there is any other new extension instance other than the OOB one, concat them together
//The extension instance with higher order number would overwrite the one with lower order number
for(var i = 0; i < ep.length; i ++){
var point = ep[i];
point.copyFieldsFromCaseToIncident(incGr, caseGr);
}
var x = new GlideRecord('cmdb_ci');
x.addQuery('name',current.u_service);
x.query();
while(x.next()){
var ci = x.sys_id;
}
var incSysId = incGr.insert();
var inc = new GlideRecord('incident');
inc.addQuery('sys_id',incSysId);
inc.query();
while(inc.next()){
inc.cmdb_ci = x;
inc.assignment_group = current.assignment_group;
inc.update();
}
caseGr.incident = incSysId;
caseGr.update();
gs.addInfoMessage(gs.getMessage("Incident {0} created", incGr.number));
uiActionHandler.openGlideRecord(incGr);
uiActionHandler.setReturnURL(caseGr);
},