g_form in workspace UI Action button returns stale values

aakashgoyal
ServiceNow Employee
ServiceNow Employee

There is a list of records in a workspace view. Clicking on a record gives an option to create a case on that record by clicking on a UI action. Lets say, you open record and click on create case. This will open up a new case record with values from clicked Record1. Now Lets say, if in parallel, another record2 is opened and click on new case, the new case record has values from Record1 rather than Record2.

 

The UI Action has a workspace client script and uses g_aw.openRecord and gets details using the g_form. Does g_form has some caching be default when it comes to workspaces?

 

If the refresh is done, the values from Record2 appear in the new case record. So it looks like some cache issue.

 

var cardNumber = g_form.getUniqueValue();

var confirmation = getMessage("");

g_aw.openRecord('case_table', -1, { mode: 'form', alerts: confirmation, context: {}, query: ""})

 

Any alternatives or good practices that can be used to prevent this.

4 REPLIES 4

Its_Azar
Tera Guru

Hey @aakashgoyal !

 

\ In Workspace, g_form can sometimes retain the previous form’s values if the client state hasn't been fully updated before the UI action executes — particularly if the card is selected and the script runs before the form load completes. One good practice is to avoid directly relying on g_form inside UI Actions in Workspace. Instead, try passing the required data explicitly from the card or use g_form.getFormContext().getField('field_name').getValue() for more reliable access in some cases. Alternatively, you can use a ViewModel-based approach or get the latest values from the GlideRecord server-side if possible, based on the record you’re clicking. 

 

If this helps kindly accept the solution thanks much.

☑️ If this helped, please mark it as Helpful or Accept Solution so others can find the answer too.




Kind Regards,

Mohamed Azarudeen Z

Developer @ KPMG

 Microsoft MVP (AI Services), India

aakashgoyal
ServiceNow Employee
ServiceNow Employee

When I try to log the values I see the uniqueValue is for the current record but it is still opening the record with the previous record. However, when I do an overall refresh, I can see the new record is for the current one. 

Ankur Bawiskar
Tera Patron
Tera Patron

@aakashgoyal 

how are you getting the details from previous record to the new record?

share that detail

In your above script you are not doing that

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

I am not getting details from the previous record. That is coming automatically which is the issue I am aksing.