- 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 08:43 AM
I used email here. This would be using a URL like...
https://<instance name>.com/nav_to.do?uri=incident.do?sys_id=-1%26sysparm_query=priority=1^incident_state=3^caller_id=abel.tuter@example.com^assigned_to=javascript:gs.getUserID()
I'm sure I'm misunderstanding how this should work, or missing something simple/silly. Either way thanks for the help!
function onLoad() {
var id;
var cID = getParmVal('caller_id');
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 09:44 AM
Assuming you are passing the user id in the URL, use the below script
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()
function onLoad() {
var id='';
var cID = getParmVal('caller_id');
var usr = new GlideRecord("sys_user");
usr.addQuery('user_name', 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;
}
}
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2018 10:03 AM
Here you go
function onLoad(){
var id;
var cID = getParmVal('sysparm_query').split("caller_id=")[1];
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: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:29 AM
This works! Thank you so much!
