How to call a data look up record data resource in client script in UI builder?

Manmaya Kumar S
Tera Expert

I am trying to execute a look up data resources in client script in UI builder but its not executing correctly.

 

find_real_file.png

I believe I am missing some parameters in the object being passed into the execute function. If anyone can help me with that it will be really appreciated.

 

Thanks!

1 REPLY 1

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hi Manmaya,

in UIB, data resources can either query (read) or mutate (create/update) data and depending on which the data resource in question does, it behaves differently in UIB. You're running into an issue where you're trying to work with the query data resource the same way you would work with a mutate data resource.

The big differences are:

Data resources that mutate data have an execute() function and are only called when they are executed, whether through a script or an event handler. Also, you pass data into these data resources when you call them (like you're doing in your script).

find_real_file.png

On the other hand, you're working with a Look up records data resource, which queries data. Data resources that query data have a refresh() function and you can't pass data to them while calling that. With a query data resource you can bind data (usually page properties, client state parameters, or the output of another data resource) to its properties and when any piece of data bound to its properties changes it should automatically refresh itself.

find_real_file.png

tl;dr - use refresh() instead of execute() and bind client state parameters to the properties of the data resource rather than trying to pass the data when you want to refresh it.