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

 

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

Thanks! Looks like I will have to contact ServiceNow for this. It's showing this script include is read-only.

You can create your own script include with these updates and call this script include from UI action.

 

Regards,

Sachin

So, I would just create a new script include and only enter the code above? But, I would need to create a new UI Action called something different than 'Create Incident', correct? 

No need to create new UI action.

Just create new script include and copy code from OOB script include and call this script include your UI action.

 

Regards,

Sachin