- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2020 09:41 AM
Hi Team.
I have a variable set for catalog items that auto-populate with basic user information based on who is logged into SN. It pulls data from the user table. The user should be able to change the user's name in the "Who is this request for?" field if submitting the request on behalf of another person. The rest of the fields should update automatically with the new user's information.
I am able to successfully do this when impersonating an ITIL user, but not when I impersonate a regular non-ITIL user. With the non-ITIL user, I am able to change the "Who is this request for?" field, but the other fields do not update. The organization's field is blank and the Phone number and Email address fields get populated with "Undefined". I have attached screenshots.
I looked through the Service Catalog properties, Catalog UI Policies and ACLs, but I did not find one that could be impacting the variable auto-population for non-ITIL users.
Any information/suggestion that you can provide me will be greatly appreciated.
Thank you.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2020 10:11 AM
EDIT: Made some changes to the code below in the script include for company. Instead of a reference variable make company a string. Then you will not have to worry about ACLs.
Here is a script include along with the updated client script. Note this still doesn't now work for company as it appears the core_company table has a read ACL on it with a bunch or roles. Not sure why. You may want to contact your ServiceNow account rep to see if it is a licensing issue to remove the roles from that ACL.
Script Include: Make sure the name of the script include is GetUserData and that you check client callable.
var GetUserData = Class.create();
GetUserData.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCompany: function () {
gs.log('in company funcation');
var gr = new GlideRecord('sys_user');
var sys_id = this.getParameter('user_sys_id');
gr.addQuery('sys_id', sys_id);
gr.query();
if (gr.next()){
return gr.getDisplayValue('company');
}
},
getPhone: function () {
var gr = new GlideRecord('sys_user');
var sys_id = this.getParameter('user_sys_id');
gr.addQuery('sys_id', sys_id);
gr.query();
if (gr.next()){
return gr.phone;
}
},
getEmail: function (){
var gr = new GlideRecord('sys_user');
var sys_id = this.getParameter('user_sys_id');
gr.addQuery('sys_id', sys_id);
gr.query();
if (gr.next()){
return gr.email;
}
},
type: 'GetUserData'
});
Updated Client script:
function onChange(control, oldValue, newValue, isLoading) {
if (newValue == '') {
return;
}
var user = g_form.getValue('requested_for');
var userCompany = new GlideAjax('GetUserData');
userCompany.addParam('sysparm_name', 'getCompany');
userCompany.addParam('user_sys_id', user);
userCompany.getXML(Company);
var userPhone = new GlideAjax('GetUserData');
userPhone.addParam('sysparm_name', 'getPhone');
userPhone.addParam('user_sys_id', user);
userPhone.getXML(Phone);
var userEmail = new GlideAjax('GetUserData');
userEmail.addParam('sysparm_name', 'getEmail');
userEmail.addParam('user_sys_id', user);
userEmail.getXML(Email);
}
function Company(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('company', answer);
}
function Phone(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('phone', answer);
}
function Email(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('email', answer);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2020 10:27 AM
I have done this before with the following.
1. Put a default value on the filed referencing the sys_user table.
2. Use an onChange client script on the field using getReference.
This has always work for me even with the OOB ACLs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2025 07:11 AM
@Brian Lancaster javascript:gs.getUserID(), This was absolutely helpful. I didnt use the client script but the autopopulate feature in the variable and it works perfectly. i added screenshots incase someone else needs it.