UI Builder: Issue with Local Data Resource

gsimoes
Tera Contributor

Hello,

I'm trying to make a modification to our landing page in Service Operations Workspace.  Basically, we've added a user field for "nickname" and we want to use that instead of the firstName that it defaults to.  I setup a local Data Resource that queries the sys_user table to get this information, but when I try to update the initialization script, it crashes when trying to read this value.  If I go to the pill selector it is: data.look_up_nickname.result.nickname.value, so I've tried adding code for api.data.look_up_nickname.result.nickname.value, but it just crashes. I know the rest of the coding works, because if I hard code a name "like x = 'Smith'" then it does exactly what is expected, but only fails when trying to read from the local data resource.  I've also replaced the dynamic text component with the local resource directly in the interface, so I can see that the data does exist, it's only when trying to read from the local data resource IN client script that I am having issues.  Any suggestions?

1 ACCEPTED SOLUTION

Hi Simoes,

It seems so.

 

1. Create a client state "nickName".

Manoj89_0-1751092166386.png

 

2. Update client state with returned value when the data fetch succeeded

Manoj89_1-1751092749429.png

3. Use the client state in your landing page, this way it works async.

 

 

 

View solution in original post

10 REPLIES 10

Can you share your JSON payload

Manoj89_0-1751039085920.png

 

gsimoes
Tera Contributor

{
"items": [
{
"id": "Greg Simoes",
"label": "name",
"value": "Greg Simoes"
},
{
"id": "Greg",
"label": "u_user_nickname",
"value": "Greg"
}
],
"result": {
"_row_data": {
"displayValue": "Greg Simoes",
"uniqueValue": "6a1045d9db43d89079bdd8f3ce961906"
},
"name": {
"displayValue": "Greg Simoes",
"value": "Greg Simoes"
},
"u_user_nickname": {
"displayValue": "Greg",
"value": "Greg"
}
}
}

try, JSON.parse(api.data.look_up_nickname.result).u_user_nickname.value

gsimoes
Tera Contributor

Still failed, but new error message:
SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

 

I think it's probably a timing issue that the data has not been retrieved yet.

gsimoes
Tera Contributor

Here's the Data Resource configuration, in case something there might be throwing things off

gsimoes_0-1751039707368.png