Reference field on ui page called via UI action on workspace is not displaying results

rambo1
Tera Guru

HI Team,

I’ve created a UI Page that includes a reference field pointing to the User (sys_user) table, and it is being triggered via a UI Action on the Change form. The functionality works as expected in the standard platform view.

However, when accessed from Service Operations Workspace, the reference field does not return any user results.

below is the code used in UI action (workspace client script) for workspace :

{
        type: 'reference',
            name: 'owner',
            label: getMessage('Owner'),
            reference: 'sys_user',
            reference_label: 'user_name',
            reference_query: true,
            mandatory: true,
            referringTable: g_form.getTableName(),
            referringRecordId: g_form.getUniqueValue()
        },
13 REPLIES 13

Ankur Bawiskar
Tera Patron
Tera Patron

@rambo1 

are you checking with admin or non-admin?

for workspace you must have written workspace client script and used g_modal.showFields()

it works differently here.

Check how reference fields work in OOTB "Copy Incident" button and do changes in yours

AnkurBawiskar_0-1753433942448.png

 

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

HI @Ankur Bawiskar , 

I am checking as admin and I am using below code :

function onClick(g_form) {
    var fields = [
        {
        type: 'reference',
            name: 'main_owner',
            label: getMessage('Owner'),
            reference: 'sys_user',
            reference_label: 'user_name',
            reference_query: true,
            mandatory: true,
            referringTable: g_form.getTableName(),
            referringRecordId: g_form.getUniqueValue()
        }
    ];

    g_modal.showFields({
        title: "Request",
        fields: fields,
        size: 'lg'
    }).then(function(fieldValues) {
        // Extract values
        var userRef = fieldValues.updatedFields.find(f => f.name === 'main_owner').value;
        var ga = new GlideAjax('it_request');
        ga.addParam('sysparm_name', 'postchangeTRrequest');
        ga.addParam('sysparm_userRef', userRef);

        ga.getXMLAnswer(function(response) {
            if (!response) {
                return;
            }
            g_form.setValue('comments', response);

            g_form.addInfoMessage('' + response);
        });
    });
}

@rambo1 

your current form has main_owner as a field which refers to sys_user? is that field name correct?

So reference field is seen but you can't select anything there?

try to hard-code the referringTable

referringTable: 'yourTableName',

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

yes field name is correct and I have tried hard coding by giving 'change_request' as referring table but it did not work.