We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

How to display a Reference variable as "Last Name First Name" in a Record Producer?

SatyamS81441163
Tera Contributor

Hi everyone,

I have a Reference variable in a Record Producer that points to the sys_user table.

Currently, the selected user is displayed as:

Ahnaf Sheik

However, I want it to be displayed in the following format:

Sheik Ahnaf (Last Name First Name)

The variable label is already "Report Entered By (Last Name, First Name)", but the reference field still displays the user's display value (First Name Last Name).

Is there a way to configure the reference variable or reference qualifier so that the selected value is displayed as Last Name First Name instead of First Name Last Name? Is this possible without changing the global display value of the sys_user table?

Any suggestions or best practices would be appreciated.

Screenshot 2026-07-16 at 12.17.23 PM.png

2 REPLIES 2

yashkamde
Mega Sage

Hello @SatyamS81441163 ,

 

Yes this can be done using client script + glide ajax :

client script (onchange) :

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var ga = new GlideAjax('setName');
    ga.addParam('sysparm_name', 'getFormattedName');
    ga.addParam('sysparm_user_id', newValue);
    ga.getXMLAnswer(function(displayName) {
        g_form.setValue('user', newValue, displayName);
    });

}

 

Script Include :

var setName = Class.create();
setName.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	getFormattedName: function() {
        var userId = this.getParameter('sysparm_user_id');
        var gr = new GlideRecord('sys_user');
        if (gr.get(userId)) {
            return gr.getValue('last_name') + ' ' + gr.getValue('first_name');
        }
        return '';
    },

    type: 'setName'
});

 

So this will setting the name as per in your desired format :

Screenshot 2026-07-16 123029.pngScreenshot 2026-07-16 123034.png

 

If my response helped mark as helpful and accept the solution.

Tanushree Maiti
Tera Patron

Hi @SatyamS81441163 

 

1) If your primary concern is helping users find records by last name while typing , you can add auto-complete columns via Variable Attributes.  (NO CODE)

 

  • Navigate to your reference variable,
  • switch to the Advanced view under Related Links,
  • and add this string into the Variable attributes field:
    ref_auto_completer=AJAXTableCompleter,ref_ac_columns=last_name;first_name,ref_ac_columns_search=true

 

TanushreeMaiti_0-1784188568605.png

 

2) 

If your functional requirements mandate keeping the variable type strictly as a Reference field, you can leverage an onChange Catalog Client script.

  • Set the Type to onChange.
  • Select your reference variable in the Variable name field.
  • Set the UI Type to All

 

function onChange(control, oldValue, newValue, isLoading) {

    if (isLoading || newValue === '') {

        return;

    }

 

    g_form.getReference('YOUR_VARIABLE_NAME', function(userRecord) {

        if (userRecord) {

            var lastName = userRecord.last_name;

            var firstName = userRecord.first_name;

            var customDisplay = lastName + ", " + firstName;

             g_form.setValue('YOUR_VARIABLE_NAME', newValue, customDisplay);

        }

    });

}

 

 

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti