How to call a look up Data source action in client script using execute function in UI builder?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-25-2022 10:35 PM
I am trying to update/create a user preference record when the user interacts with the UI page built using UI builder. For that we will have to perform a look up into the user preference table in servicenow. But I am not sure how to access that data resource in UI builder client script. I was trying something like this:-
But its not working properly. So may be there's something else we need to pass in the execute function.
Any help will be highly appreciated.
Thanks.
- Labels:
-
Now Experience UI Framework

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-26-2022 06:34 AM
I'm just learning UI Builder now so I may be wrong here...
Using look_up_record if for reading not writing am I right?
If it is reading the current users preference you need, that is already available to the scripts is it not via something like...
api.context.session.userPrefs["user.preference.name"];
Otherwise do you not need to Update Record data resource?
It says it is of type GRAPHQL which I assume means it maps to this definition...
https://<yourInstance>.service-now.com/now/nav/ui/classic/params/target/sys_ux_data_broker_graphql.do%3Fsysparm_query%3Dname%3DUpdate%2520Record
Which I think means it is this that is dictating the payload you need to send.
I've played a little bit with Graphql but I am not very experienced with it, I will try and figure out how to use it..
So, looking at the definition of that Graphql data broker...
[
{
"name": "table",
"label": "Table",
"description": "Target table to edit",
"readOnly": false,
"fieldType": "table_name",
"mandatory": true,
"defaultValue": ""
},
{
"name": "recordId",
"label": "Record",
"description": "Record to edit",
"readOnly": false,
"fieldType": "reference",
"mandatory": true,
"defaultValue": "",
"typeMetadata": {"reference": "@table"}
},
{
"name": "templateFields",
"label": "Field Values",
"description": "Field value map to apply",
"readOnly": false,
"fieldType": "condition_string",
"mandatory": true,
"defaultValue": "",
"typeMetadata": {
"table": "@table"
}
},
{
"name": "useSetDisplayValue",
"label": "Use Display Values",
"description": "Use display values when updating the record",
"readOnly": false,
"fieldType": "boolean"
}
]
It suggest you need the recordId, so if you don't have that do you have to do a lookup first to see if it exists, then pass that into an Update Record call if it exists or call Create Record if it doesn't?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2022 07:08 AM
Hi Manmaya,
Please take a look at your other post where I addressed this: https://community.servicenow.com/community?id=community_question&sys_id=8013b92ddba91194dd886c8e1396...
The main issue is that you can't pass data to a query data resource at the time you're calling it. You have to bind data to the data resource and then refresh() it instead of executing it.