- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2025 08:23 PM
Hi, People
I have to auto-populate several fields on a variable catalog item based on 'requested for'.
**I have it done over the auto-populate feature - the challenge is not to use it -
I have created the catalog client script and auto-populated the needed field but for location is displaying the sys ID --
Searching over the community, I'm missing the script include, also struggling on how to configure it done!
thanks in advance for any help!!!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-21-2025 12:42 PM
Thank you for all your help, I solved it the following way.
Script include
Name: getUserDetails --
Glide AJAX enabled: TRUE --- client callable ---
Script
var getUserDetails = Class.create();
getUserDetails.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getUserInfo: function() {
var userID = this.getParameter("sysparm_userID");
var userGr = new GlideRecord("sys_user");
userGr.addQuery("sys_id", userID);
userGr.query();
if (userGr.next()) {
var obj = {};
obj.rfname = userGr.getDisplayValue("first_name");
obj.rmname = userGr.getDisplayValue("middle_name");
obj.rlname = userGr.getDisplayValue("last_name");
obj.rlocation = userGr.getDisplayValue("location");
obj.remail = userGr.getDisplayValue("email");
obj.rmphone = userGr.getDisplayValue("mobile_phone");
obj.rptitle = userGr.getDisplayValue("title");
obj.renumber = userGr.getDisplayValue("employee_number");
obj.rntid = userGr.getDisplayValue("u_string_1");
var json = new JSON();
var data = json.encode(obj);
return data;
}
},
type: 'getUserDetails'
});
Catalog Client Script
Name: Requestor information
Type: onChange
Variable name: Requestor Details >> requeted_for -- 'Requestor Details' = Variable set // 'Requested For' = variable --
Script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('getUserDetails');
ga.addParam('sysparm_name', 'getUserInfo');
ga.addParam('sysparm_userID', newValue);
ga.getXML(callback);
function callback(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
answer = answer.evalJSON();
g_form.setValue("requestor_first_name", answer.rfname);
g_form.setValue("requestor_middle_name", answer.rmname);
g_form.setValue("requestor_last_name", answer.rlname);
g_form.setValue("requestor_location", answer.rlocation);
g_form.setValue("requestor_email", answer.remail);
g_form.setValue("requestor_contact_no", answer.rmphone);
g_form.setValue("requestor_employee_number", answer.renumber);
g_form.setValue("requestor_position_title", answer.rptitle);
g_form.setValue("users_network_id", answer.rntid);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2025 08:31 PM
Hi @tom the
Using getReference method you can only dot walk to one level. As you are already dot walking to user table so you can not dot walk further to get location fields.
You can use a client callable script include and call the script include in your client script using GlideAjax.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2025 08:44 PM
Ok, thank you for that information.
Yes, as far as I am searching, I am missing the script include, I am trying to understand how to configure it and how to include (call) from the catalog script include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2025 09:24 PM
You write script include and call it from catalog client script
if my answer helps you mark helpful and accept solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2025 09:14 PM
your getReference with callback should also work fine, no script include required.
Your location variable should be referring to cmn_location table and script should work fine
If your location variable is string then you can use onChange + GlideAjax and get the location name and then set it
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader