- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2022 08:39 AM
HI All,
(Catalog Item) I am trying to get the variable 'location' to auto populate with the requester information. Initially, the location populates with the signed in requester because I have a default javascript in place that does that. If I change the user, the OnChange script is supposed to set the value for that user, instead it displays the sys id. I did check the display on the location table and it's set to true on name. I am out of ideas. Please help!
I will include the variable default code and the Catalog client script. Also, the location variable is set to a single line text variable.
*I have tried both options that are commented out. The above script works for phone and email variables.
*Location (Single line text variable) to populate 'Requester' (variable set variable) Location
Thanks,
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2022 09:48 AM
Thank you all for your help! I used this code and it helped.
Script Include
var getLocation = Class.create();
getLocation.prototype = Object.extendsObject(AbstractAjaxProcessor, {
get_location: function() {
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', this.getParameter('sysparm_userID'));
gr.query();
if (gr.next()) {
return gr.location.getDisplayValue();
}
},
type: 'getLocation'
});
OnChange Catalog Client script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('getLocation');
ga.addParam('sysparm_name', 'get_location');
ga.addParam('sysparm_userID', g_form.getValue('requester')); //the variable name from the variable set
ga.getXMLAnswer(function(answer){
//if(answer != ''){
g_form.setValue('location', answer);
//}
});
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2022 09:00 AM
Hi,
This dot walk feature on will not work on the getReference function. you will have yo use GlideAjax and then return the fields needed from server side
-Anurag
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2022 09:04 AM
Please try to use GlideAjax Call in order to get the display value of location field. You can return multiple values from Script Include using JSON object. Please try the below code in Script Include.
getUserData: function() {
var gruser = new GlideRecord('sys_user');
var user = this.getParameter('sysparm_user');
if (gruser.get(user)) {
var json = new global.JSON();
var results = {};
results.first_name = gruser.getValue('email');
results.last_name = gruser.getValue('phone');
results.location= gruser.getDisplayValue('location');
return json.encode(results);
}
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2022 09:48 AM
Thank you all for your help! I used this code and it helped.
Script Include
var getLocation = Class.create();
getLocation.prototype = Object.extendsObject(AbstractAjaxProcessor, {
get_location: function() {
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', this.getParameter('sysparm_userID'));
gr.query();
if (gr.next()) {
return gr.location.getDisplayValue();
}
},
type: 'getLocation'
});
OnChange Catalog Client script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('getLocation');
ga.addParam('sysparm_name', 'get_location');
ga.addParam('sysparm_userID', g_form.getValue('requester')); //the variable name from the variable set
ga.getXMLAnswer(function(answer){
//if(answer != ''){
g_form.setValue('location', answer);
//}
});
}