Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

Catalog Item in Workspace Prefills Old Record Data When Opened from Different Records

Nirma Sai E
Tera Contributor

We are opening a Record Producer from an agent record in the Configurable Workspace using a client-side UI Action.

The parent record sys_id of the agent is being passed and used in the on load client script in the record producer to prefill a variable (user) in it.

The issue is that when the record producer tab remains open, and we navigate to another agent and trigger the same action again, the previously populated sys_id is retained rather than being refreshed with the new record’s sys_id and the same tab is being opened.

We are currently using client-side parameter passing and local storage to transfer the sys_id.

Has anyone implemented a reliable way to pass parent record context to a catalog item in Configurable Workspace without stale data issues?
Or the problem is in how we are opening the Record producer?

1 ACCEPTED SOLUTION

Hi @Nirma Sai E @Ankur Bawiskar , 

Yeah, I tested it more after your message and you’re right, just using g_aw.openRecord() and reading the sys_id from the URL doesn’t fully fix it.

The real issue is that Workspace reuses the same Record Producer tab if it’s already open. So even though the URL changes, the component itself doesn’t reload, and the onLoad script only runs the first time. That’s why the old value stays.

So it’s not really a parameter passing issue , it’s how Workspace handles tab reuse.

What worked for me was not relying only on onLoad, but instead watching for URL changes and updating the field when the parent_sys_id changes. Since Workspace updates the route but keeps the component alive, we need to handle that manually.

Something like this, this script checks the URL every 500 milliseconds and updates the field only if the sys_id changes:

function onLoad() {
    var lastSysId = '';
    setInterval(function() {
        var url = decodeURIComponent(top.location.href);
        if (url.indexOf('extra-params/') > -1) {

            var params = url.split('extra-params/')[1].split('/');
            var currentSysId = params[1];

            if (currentSysId && currentSysId !== lastSysId) {
                lastSysId = currentSysId;
                g_form.setValue('manager', currentSysId);
            }
        }
    }, 500);
}

 

View solution in original post

10 REPLIES 10

Ankur Bawiskar
Tera Patron

@Nirma Sai E 

yes this happened with me as well.

didn't find any concrete solution for this.

💡 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

Thanks for taking some time on this @Ankur Bawiskar  😌 

Vaibhav Chouhan
Tera Guru

In Configurable Workspace, the issue is usually not the Record Producer itself but how parameters are passed and read.

If you’re using localStorage to transfer the parent sys_id, that can cause stale data when the tab is reused. Workspace reuses the same component instance, so stored values may persist.

Instead, you can pass the value directly using g_aw.openRecord() and read it from the Workspace route. Official Documentation: GlideAgentWorkspace (g_aw) | ServiceNow Developers

UI Action: 

g_aw.openRecord('sc_cat_item', 'record_producer_sys_id', {
    parent_sys_id: g_form.getUniqueValue()
});

In Configurable Workspace, parameters are not passed as normal query strings (?param=value). They are embedded in the route under /extra-params/

So in the Record Producer onLoad Client Script, you can extract it from the URL like this:

function onLoad() {

    var url = decodeURIComponent(top.location.href);

    if (url.indexOf('cwf/agent') > -1) {

        var workspaceParams = url.split('extra-params/')[1];
        var allParams = workspaceParams.split('/');

        var sysId = allParams[1];

        if (sysId) {
            g_form.setValue('manager', sysId);
        }
    }
}

 

@Vaibhav Chouhan 

did you test it with different records?

share working screenshots

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