- 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 09:53 AM
Can you provide the script you are using to get the values for the other fields? I have done this before and it worked for everybody.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2020 06:09 PM
Hi Brian.
Here are the scripts.
OnLoad:
function onLoad() {
g_form.setValue('requested_for',g_user.getFullName());
var requesterinfo=new GlideRecord('sys_user');
requesterinfo.addQuery('sys_id',g_user.userID);
requesterinfo.query();
while (requesterinfo.next())
{
g_form.setValue('company',requesterinfo.company);
g_form.setValue('phone',requesterinfo.phone);
g_form.setValue('email',requesterinfo.email);
}
}
OnChange:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var requestersysid=g_form.getValue('requested_for');
var requesterinfo=new GlideRecord('sys_user');
requesterinfo.addQuery('sys_id',requestersysid);
requesterinfo.query();
while (requesterinfo.next())
{
g_form.setValue('company',requesterinfo.company);
g_form.setValue('phone',requesterinfo.phone);
g_form.setValue('email',requesterinfo.email);
}
}
I've attached screenshots as well.
Thanks for your help.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2020 07:05 PM
In your variable for requested_for on the default value tab put javascript:gs.getUserID() in the default value field. Then you can disable the onLoad client script.
Change the onChange Client script to below.
function onChange(control, oldValue, newValue, isLoading) {
if (newValue == '') {
return;
}
g_form.getReference('requested_for', callBack);
}
function callBack(user) {
g_form.setValue('email', user.email);
g_form.setValue('company', requested_for.company);
g_form.setValue('phone', requested_for.phone);
}
Note that you should not use glide record in client script as it will not work in mobile or service portal. It is best to use GlideAjax or a built in function like getReference.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2020 10:00 AM
Hi Brian.
Thanks for your suggestion.
I tried it and now the Company and Phone number fields do not populate for either the ITIL and non-ITIL users. The email address field populates fine.
I am thinking that the company field issue may be in that it is a Reference field as well using the core.company table. Here is the configuration for it in case it helps.
But I cannot figure out why the phone field is not populating now.
Any suggestions will be greatly appreciated.
Thanks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2020 11:25 AM
Sorry typos in my script
function onChange(control, oldValue, newValue, isLoading) {
if (newValue == '') {
return;
}
g_form.getReference('requested_for', callBack);
}
function callBack(user) {
g_form.setValue('email', user.email);
g_form.setValue('company', user.company);
g_form.setValue('phone', user.phone);
}