Convert Incident to Case and vice versa

Steve Kelly
Mega Sage

Hello community!

I came across an article on Hi about how to do a basic conversion of an Incident record to a Request record:
https://hi.service-now.com/kb_view.do?sysparm_article=KB0694006

The article seems pretty straightforward. However, we have an implementation in our instance of both ITSM and CSM, and we have a need to convert Incidents to Cases and vice versa.

I tried copying the steps for Incident to Case but they did not work, I suspect because CSM is a scoped app. I tried modifying the client script to do a GlideAjax call with a script include instead but could not get it working. 

Has anyone done this or know if it is possible?

Thanks,

Steve

5 REPLIES 5

Uncle Rob
Kilo Patron

ALlt he images are coming up broken for me on that KBA.  But why don't we take a look at your script and tell us the nature of the results you get.

Thanks Robert. If you log into Hi you will see the images (this is behavior I have noticed with pasted images on public KB articles on our own instance. Properly inserted images do display).

Here is what I have so far. I went with a script include as I read in another post that GlideRecord will not work in CSM because it is scoped. However, I am not a developer by background so there may be errors...

UI Action Script

var you_are_elle_path = 'sn_customerservice_case.do?sysparm_incident_id=' + current.sys_id;
action.setRedirectURL(you_are_elle_path);

 

Client Script on Case table

Type: onLoad

function onLoad() {
	//Verify the correct incident sysparm is in the header
	var gURL = newGlideURL();
	gURL.setFromCurrent();
	var incidentID = gURL.getParam('sysparm_incident_id');
	
	if(incidentID){
		//Use the passed sys_id to create a new GlideRecord object
		var ga = new GlideAjax('global.ConvertIncCaseUtils');
		
		ga.addParam('sysparm_name', 'getIncDetails');
		ga.addParam('sysparm_incsysid', incidentID);
		ga.getXML(function(response) {
			
			var answer = response.responseXML.documentElement.getAttribute("answer");
			var answers = answer.split(',');
			console.log(answers);
			
			g_form.setValue('contact', answers[0]);
			g_form.setValue('opened_at', answers[1]);
			g_form.setValue('opened_by', answers[2]);
			g_form.setValue('short_description', answers[3]);
			g_form.setValue('description', answers[4]);
			
		});
			/*var grINT = new GlideRecord('incident');
			grINT.get(incidentID);
			
			var thisSD = g_user.getClientData('short_description');
			
			//Map the appropriate fields to the Case record
			g_form.setValue('contact', grINT.caller_id);
			g_form.setValue('opened_at', grINT.opened_at);
			g_form.setValue('opened_by', grINT.opened_by);
			g_form.setValue('short_description', thisSD);
			g_form.setValue('description', grINT.description);*/
	}
}

 

Script Include

Application: Global

Accessible from all scopes

Client Callable

var ConvertIncCaseUtils = Class.create();

ConvertIncCaseUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getIncDetails: function(){


var retVal; // Return value
var incID = this.getParameter('sysparm_incsysid');

var grInc   = new GlideRecordSecure('incident');
grInc.addQuery('sys_id',incID);
grInc.query();

// Query incident


if(grInc.next()){

retVal = grInc.caller_id+','+grInc.opened_at+','+grInc.opened_by+','+grInc.short_description+','+grInc.description;

}

return retVal;

},

    type: 'ConvertIncCaseUtils'
});

Rich Dennis
Tera Expert

CSM is a Scoped App. Check the Case table's Application Access.

 

https://docs.servicenow.com/bundle/london-application-development/page/build/applications/concept/c_ExampleGrantingAccessToConfigRecs.html 

Hey Rich,

So I would need to create an application access entry for the Customer Service application to Global? Do you know what parameters I would need to add?

Thanks,

Steve