How do I link to a record in servicenow?

dmitch
Kilo Contributor

I want to be able to generate URLs for use outside of ServiceNow which link to specific records by number. For example I can link to /incident.do?sysparm_query=number=INC1000 for an Incident but that URL won't work if the record is a RITM or CHG. For a CHG I can link to /change_request.do?sysparm_query=number=CHG12345 and that will work but only for that type of record. I can link to /task.do and that works for any subtype of Task but only display the generic fields for a Task, not the Change or Incident specific fields. Is there a built-in URL in ServiceNow which will display the appropriate view for any subtype of Task? Trying to have the originating web application predict what type of record type it should generate a URL for based on the ticket number is possible but would like be a brittle and clunky solution. It seems much cleaner to try and let ServiceNow do it since it can easily determine what the correct type is. 

1 REPLY 1

Matt Saxton - G
Kilo Guru

Hi, dmitch,

 

I took the liberty of writing a processor that will do the trick.  I have attached an update set that will work great. 

Before anyone code shames me..I spent almost 2 hours on a bug for this. There's an issue with processors converting input to strings. I needed this to be a string to do regex properly. I'm running madrid and i think it's deffinatly a bug. I wrote a workaround which should work regardless of the instance version. 

 

(function process(g_request, g_response, g_processor) {
	//Lets remove the numbers so we can look up the prefix.
	var idNumber = g_request.getParameter("number").toString();
	if(idNumber != ''){
		var pFix = new GlideRecord('sys_number');
		//This looks crazy on purpose. Issues with converting to strings.
		pFix.get(JSON.stringify(idNumber).replace(/\d/g, "").replace(/['"]+/g, ''));
		g_response.sendRedirect(pFix.category+'.do?sysparm_query=number='+idNumber);
		
	} else {
		//You should write some error handeling
		
	}
	
})(g_request, g_response, g_processor);

 

Once installed to use do this. 

 

https://yourinstance.service-now.com/getRecordByNumber.do?number=yournumber