Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

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

24 REPLIES 24

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).

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

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:

find_real_file.png

On Case form:

find_real_file.png

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

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?

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