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

7 REPLIES 7

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

Ankur Bawiskar
Tera Patron

@SatyamS81441163 

Not possible since on user table name field is Display=true and it holds First name + Last Name

The only option for you is

1) create a text type variable and set it with Last Name + First Name onChange of user and make that variable readonly

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

Suryansh Verma
Mega Sage

@SatyamS81441163 

 

The requirement cannot be achieved permanently on the same Reference variable without changing the display value of the referenced sys_user table.

A reference variable stores the user’s sys_id, not the displayed name. Whenever the record is reopened in Native UI, lists, reports, or variable editor, ServiceNow resolves that sys_id using the display field of sys_user, which is normally sys_user.name.

 

A reference qualifier will not solve this because it only controls which records are available for selection, it does not change their display values.

 

Recommended implementation

Keep two values on the created record:

 

Field Type Purpose
u_report_entered_byReference → sys_userStores the actual user relationship
u_report_entered_by_displayStringStores Last Name First Name

 

This preserves reporting, workflows, notifications, dot-walking and user relationships while also meeting the required display format.

 

Record Producer script

Assuming the reference variable is named report_entered_by:

 

(function populateReportEnteredBy() {

    var userSysId = (producer.report_entered_by || '') + '';

    if (!userSysId) {
        return;
    }

    var userGR = new GlideRecord('sys_user');

    if (!userGR.get(userSysId)) {
        return;
    }

    var lastName = userGR.getValue('last_name') || '';
    var firstName = userGR.getValue('first_name') || '';

    var formattedName = lastName;

    if (firstName) {
        formattedName += (formattedName ? ' ' : '') + firstName;
    }

    // Retain the real reference
    current.setValue(
        'u_report_entered_by',
        userGR.getUniqueValue()
    );

    // Store the required formatted value
    current.setValue(
        'u_report_entered_by_display',
        formattedName
    );

})();

 

Do not call current.update() in the Record Producer script.

 

The created record will contain: Report Entered By: Ahnaf Sheik

as the reference display value, while the custom string field will contain: Report Entered By – Last Name First Name: Sheik Ahnaf

 

You can place the formatted string field on the Native UI form and make it read-only.