Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

How to get actual display value instead of sys_id in below code

pk16514
Tera Contributor
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

   //Type appropriate comment here, and begin script below
   var mng = g_form.getReference('u_name', ManagerDetails);
   function ManagerDetails(mng) {
	g_form.setValue('u_manager', mng.manager);
	g_form.setValue('u_phone_number', mng.mobile_phone);
   }
}

pk16514_0-1701847972966.png

Manager field is showing sys_id, I want the display value. I tried .getValue and .getDisplayValue didn't work.

Also how to modify the above client script with callback function

1 ACCEPTED SOLUTION

SP22
Giga Sage

Hi @pk16514 

 

can you please try below script.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    //Type appropriate comment here, and begin script below
    var mng = g_form.getReference('u_name', ManagerDetails);

    function ManagerDetails(mng) {
        var manager = mng.manager;
        var phoneNumber = mng.mobile_phone;

        // Retrieving display values for the manager reference field
        var managerGR = new GlideRecord('user_table'); // Replace 'user_table' with the actual table name
        if (managerGR.get(manager)) {
            g_form.setValue('u_manager', managerGR.getDisplayValue()); // Sets the display value of the manager field
            g_form.setValue('u_phone_number', phoneNumber); // Sets the phone number value
        }
    }
}

View solution in original post

4 REPLIES 4

Danish Bhairag2
Tera Sage

Hi @pk16514 ,

 

Plz find the updated code.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

   //Type appropriate comment here, and begin script below
   var mng = g_form.getReference('u_name', ManagerDetails);
   function ManagerDetails(mng) {
	g_form.setValue('u_manager', mng.manager.getDisplayValue());
	g_form.setValue('u_phone_number', mng.mobile_phone);
   }
}

 

Thanks,

Danish

 

pk16514
Tera Contributor

Thanks Danish for your answer but now it doesn't show either the caller manager and caller phone number.

SP22
Giga Sage

Hi @pk16514 

 

can you please try below script.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    //Type appropriate comment here, and begin script below
    var mng = g_form.getReference('u_name', ManagerDetails);

    function ManagerDetails(mng) {
        var manager = mng.manager;
        var phoneNumber = mng.mobile_phone;

        // Retrieving display values for the manager reference field
        var managerGR = new GlideRecord('user_table'); // Replace 'user_table' with the actual table name
        if (managerGR.get(manager)) {
            g_form.setValue('u_manager', managerGR.getDisplayValue()); // Sets the display value of the manager field
            g_form.setValue('u_phone_number', phoneNumber); // Sets the phone number value
        }
    }
}

SanjivMeher
Mega Patron
Mega Patron

dot walk mayn't work. You may try using a display business rule to and get the user information and then pass the data in scratchpad to client script.

In this thread, there is a good example

https://www.servicenow.com/community/itsm-forum/usage-of-display-business-rule-with-client-script/m-...


Please mark this response as correct or helpful if it assisted you with your question.