- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-15-2025 07:35 AM
Hi everyone,
I'm encountering an issue with a ServiceNow catalog item, where I'm trying to auto-populate the "Current Manager," "Current Email Address," and "Current Location" fields based on the user selected in the "Contractor" reference field.
I've implemented a Client Callable Script Include ("ContractorUserDetails") that uses GlideRecordSecure to fetch these details from the sys_user table. This script include is called via client script when the "Contractor" field changes.
The Problem:
The auto-population works perfectly for users with the admin roles. what ever the user is selected in 'contract' field but for non admin and non itil users it displays the details when he selected only his own name, when tried to select other user not showing. Screenshots added below for reference.
Below is the scripts and needed information
Script include:
var ContractorUserDetails = Class.create();
ContractorUserDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
contractorDetails: function() {
var contractorUser = this.getParameter('sysparm_value');
var userDetails = {};
if (!contractorUser) {
gs.error("ContractorUserDetails: sysparm_value is missing.");
return JSON.stringify(userDetails);
}
var gr = new GlideRecordSecure('sys_user');
gr.addQuery('sys_id', contractorUser);
gr.query();
if (gr.next()) {
userDetails.manager = gr.manager.getDisplayValue();
userDetails.email = gr.email.getDisplayValue();
userDetails.location = gr.location.getDisplayValue();
return JSON.stringify(userDetails);
} else {
gs.error("ContractorUserDetails: No user found for sys_id: " + contractorUser);
return JSON.stringify(userDetails);
}
},
type: 'ContractorUserDetails'
});
Client script :
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var contractorId = g_form.getValue('contractor');
var currentUser = g_user.userID;
var ga = new GlideAjax('ContractorUserDetails');
ga.addParam('sysparm_name', 'contractorDetails');
ga.addParam('sysparm_value', contractorId);
ga.getXML(processUserDetails);
function processUserDetails(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
if (answer) {
var userDetails = JSON.parse(answer);
g_form.setValue('current_manager', userDetails.manager);
g_form.setValue('current_email_address', userDetails.email);
g_form.setValue('current_location', userDetails.location);
if (userDetails.manager && userDetails.manager_sys_id != currentUser) {
g_form.addErrorMessage('You are not listed as a Manager for the selected contractor. Please verify the correct contractor was selected. The listed manager will be asked to approve all requests submitted by someone other than themselves.');
}
}
}
}
Script include ACL :
Service catalog:
logged in user and contractor is same
Logged in user and contractor is different
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-15-2025 08:35 AM
why not use GlideRecord?
you will have to see which ACL is blocking
Also remember since you are doing GlideRecordSecure and you are accessing location so ACL on location table will also come into picture
are you getting rowcount as 0 in your query when you use GlideRecordSecure?
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-15-2025 07:43 AM
Since you are using GlideRecordSecure ACLs will evaluate
Some ACL is blocking
if you are using this for snc_internal user then why not use GlideRecord
Another way is no scripting and use Auto populate feature
Auto-populate a variable based on a reference type variable (Utah)
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-15-2025 07:56 AM
Here i need to display a warning message so i decided to write script you can check client script for more info please suggest me more to sort this out
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-15-2025 08:35 AM
why not use GlideRecord?
you will have to see which ACL is blocking
Also remember since you are doing GlideRecordSecure and you are accessing location so ACL on location table will also come into picture
are you getting rowcount as 0 in your query when you use GlideRecordSecure?
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2025 08:35 PM
Hope you are doing good.
Did my reply answer your question?
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