- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2018 10:53 AM
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.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2018 10:06 AM
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;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2018 10:16 AM
You could create a helper function that will get the User's SysID based on email and use that in your URL.
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()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2018 10:29 AM
I will give this a try, I like the idea of having the helper function.
