Updating user details on change on catalog item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
I have some fields that I use in a variable set that is meant to show some user details when a users name is selected:
eg - Add a users name "Joe Dirt" and 3 other fields update automatically to show the users logon ID, email address and department for example. Change the name that is in there already and the new users details update in the 3 other fields.
Now I am well aware of the "auto-populate" option in a variable and have tried it. It works for me, but here is the catch, it is not working for a standard user, only for those with a role such as ITIL or Business Stakeholder
So when Jane wants to log a request for Joe to get access to something and the resolver team requires that Joe's email, logon ID and Department are filled in, it will not populate for her.
Anyone know how I can fix this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hi @dannyprime
The root cause is that auto-populate fires a direct query in the context of the logged-in user's session. So when Jane (a standard user with no elevated role) tries to look up Joe's details, she doesn't have read access to the sys_user table beyond her own record — and ServiceNow just silently returns nothing. No error, just blank fields. Meanwhile your ITIL users have broader sys_user visibility so it works fine for them.
The fix I'd recommend is a GlideAjax approach:
Ditch the native auto-populate for this scenario and instead use a Catalog Client Script (onChange on your name/user field) that calls a client-callable Script Include. The Script Include runs server-side, so it does the sys_user lookup under server context and sidesteps the permission issue entirely. Jane's session never needs direct table access.
1.Script Include:-
var GetUserDetails = Class.create();
GetUserDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserDetails: function() {
var userId = this.getParameter('sysparm_user_id');
var result = {};
var gr = new GlideRecord('sys_user');
if (gr.get(userId)) {
result.user_name = gr.getValue('user_name');
result.email = gr.getValue('email');
result.department = gr.getDisplayValue('department');
}
return JSON.stringify(result);
},
type: 'GetUserDetails'
});2. Catalog Client Script (onChange)
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || !newValue) {
g_form.setValue('logon_id', '');
g_form.setValue('email', '');
g_form.setValue('department', '');
return;
}
var ga = new GlideAjax('GetUserDetails');
ga.addParam('sysparm_name', 'getUserDetails');
ga.addParam('sysparm_user_id', newValue);
ga.getXMLAnswer(function(answer) {
var details = JSON.parse(answer);
g_form.setValue('logon_id', details.user_name);
g_form.setValue('email', details.email);
g_form.setValue('department', details.department);
});
}
I hope my response helps. if yes then kindly mark helpful & Accept as Solution 🙂
Regards
Sumit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hi @dannyprime , Here is your solution.
- Populate the email and username of the user on the record producer form and make it read only.
Ans- script- onload(), Ui type – All
use a reference variable and made that variable read only (if needed) by that form itself, and in the default value (related list) wrote this code,
“javascript:gs.getUserID();”.
var userAd = g_user.email;
g_form.setValue(‘u_mail’, userAd);
g_form.setReadOnly(‘u_mail’, true);
Since all fields that you want to auto-populate are reference type this should work fine. Just make sure to make variable as reference type.
If this helps you please mark it as helpful or if this answer solves your requirement then mark this as accepted solution.
Regards,
Saurabh V.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hi dannyprime
It seems for your standard user ( example they have snc_internal role), they dont have read access on sys_user table.
I will recommend you for that for standard user's role , you can create field level Read ACL , so that they can see specific field of User table only.
Note: It should be managed carefully via ACLs to avoid exposing sensitive data to all employees.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Hello @dannyprime
Hello @dannyprime ,
As mentioned by @Tanushree Maiti standard users have some restriction that enforce by acl on sys_user table .Thats why email,departments are not readable/visible to standard users .
you can resolve this issue by creating field level acls for email,department fields which will give you read access otherwise by using glideajax you can fetch relevant data and set that in your variables but it seems long process .
If this helps you then mark it as helpful and accept as solution.
Regards,
Aditya,
technical Consultant
