End user unable to see other user details

shaik23
Tera Expert

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 :

shaik23_0-1747319542996.png

 

shaik23_1-1747319572850.png


Service catalog:

logged in user and contractor is same

shaik23_2-1747319625953.png

Logged in user and contractor is different

shaik23_3-1747319680348.png

 

 
 
 
 
 
1 ACCEPTED SOLUTION

@shaik23 

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.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

5 REPLIES 5

@Ankur Bawiskar 

Yes your suggestion works i kept as it is but changed GlideRecord  from GlideRecordSecure