Creating an Incident from a Case

MStritt
Tera Guru

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?

find_real_file.png

 

1 ACCEPTED SOLUTION

 

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

View solution in original post

23 REPLIES 23

I updated the script include with this code. But when I click on 'Create Incident' on the Case, it takes me to Case list view. It doesn't create an incident.

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);
	},

This is happending since cmdb_ci is a reference field on incident table and it expects sys_id of CI from cmdb_ci table.

But, in your case, u_service is a string field.

You need to query cmdb_ci table and match name from u_service field and get sys_id.

 

Regards,

Sachin

 

 

Would it be easiest to make Configuration Item field on the Incident a choice field? Than add the same 20 choices I have on the Service field on the Case?

Don't change data type of incident table CI field since this is OOB field and it will break lot of things.

 

Instead, change data type of u_service field to reference like incident CI field 

 

OR

 

use above code i provided to query cmdb_ci table with name.

 

Regards,

Sachin

On the Case, we only want to give the agent certain choices (the 20 I created). Not to have to search for these specific choices.

I think what the issue might be, is that in our DEV instance, we don't have these 20 choices in the cmdb_ci table. Looks like they are only in our PROD instance. So, that might be why it's not being populated. I'll add one of these choices in the cmdb_ci table, then see if it works.