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

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi,

You need to include the additional fields in script include "ServiceManagementIncidentUtils".

 

- Pradeep Sharma

Thanks. Here's the portion in the Script include that references Create Incident From Case. How would I update this portion to include these 2 values?

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();
		caseGr.incident = incSysId;
		caseGr.update();
		gs.addInfoMessage(gs.getMessage("Incident {0} created", incGr.number));
		uiActionHandler.openGlideRecord(incGr);
		uiActionHandler.setReturnURL(caseGr);
	},

Jaspal Singh
Mega Patron
Mega Patron

Hi,

 

ServiceManagementIncidentUtils() is a script include with function createIncdientFromCase() can you check the function & try passing the required values once.

MStritt
Tera Guru

So:

Case                           Incident

u_service              --> cmdb_ci

assignment_group --> assignment_group