Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Create an Incident from URL but...

Patrick51
Giga Contributor

So I'm creating an application for an IT help desk. The idea is the customer will walk up to the help desk and swipe an RFID card. Through the application we will gain information like the users first name and last name or an email. With that email I want to use a URL to populate an incident report. like..

URL: https://<instance name>.service-now.com/nav_to.do?uri=incident.do?sys_id=-1%26sysparm_query=priority=1^incident_state=3^caller_id=abel.tuter^assigned_to=javascript:gs.getUserID()

For this IT desk the assigned to will be the currently logged in user. That works great with the above URL. I run into a problem when I want to get the caller. The caller will be the walk up customer. 

So my question is what can I do to achieve what I'm going for? I will have access to the back end so I can write whatever need be to achieve this. Ideally there would be some work around with just the URL but if that does not work I'm open to whatever. I think it needs to be something like I would have a script that could search up an ID based on the callers name or email. I'm just unsure how to parse caller_id since it is a reference. 

1 ACCEPTED SOLUTION

Abhinay Erra
Giga Sage

Here is the correct code

 

function onLoad(){

var id;
var cID ='';

var parmArr=getParmVal('sysparm_query').split("^");

for(i=0; i<parmArr.length; i++){

if(parmArr[i].indexOf("caller_id")>-1){

cID=parmArr[i].split("=")[1];

break;

}

}
var usr = new GlideRecord("sys_user");
usr.addQuery('email', cID);
usr.query();
if(usr.next()) {
id = usr.sys_id; //this will get you the sys_id of the user
}

if(id) {
g_form.setValue('caller_id', id);
}

}
function getParmVal(name){
var url = document.URL.parseQuery();
if(url[name]){
return decodeURI(url[name]);
}
else{
return;
}
}

View solution in original post

11 REPLIES 11

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

You could create a helper function that will get the User's SysID based on email and use that in your URL.

find_real_file.png

 

Here is the script:

function getUserByEmail(email) {
	var answer = "";
	
	var userRec = new GlideRecord("sys_user");
	userRec.addQuery("email", email);
	userRec.addActiveQuery();
	userRec.query();
	if (userRec.next()) {
		answer = userRec.sys_id;
	}
	
	return answer;
}

Then your URL becomes:

https://<instance name>.service-now.com/nav_to.do?uri=incident.do?sys_id=-1%26sysparm_query=priority=1^incident_state=3^caller_id=javascript:getUserByEmail("EMAIL ADDRESS OF USER")^assigned_to=javascript:gs.getUserID()

I will give this a try, I like the idea of having the helper function.