UI Builder: Client script to format data resource after REST broker fetch

TFischer
Tera Expert

Hello,

 

I have configured a data resource to fetch a payload via REST api. I can see the data is being successfully fetched. I was hoping to achieve the following,

 

Fetch data resource -> format via client script -> set formatted data as client state property

 

On the data resource I was able to find the "Data Fetch Succeeded" event, which I assume is where I'd want to assign a formatting client script. However, I wasn't sure how to reference that data payload in the specified script.

 

TFischer_0-1736952809837.png

 

1 ACCEPTED SOLUTION

IronPotato
Mega Sage

Hi @TFischer ,

 

in your client script which is attached to "Data Fetch Succeeded", access your data like this:

 

api.data.<name of your DR that should return result>.<variable name that you have defined in your output schema in DR record>

 

as an example:

 

const clientData = api.data.getClinetDataFromApi.result;

console.log('clientData', clientData);

 

// transform your data

 

If my answer helped you in any way, please then mark it as helpful or correct. This will help others finding a solution.

View solution in original post

1 REPLY 1

IronPotato
Mega Sage

Hi @TFischer ,

 

in your client script which is attached to "Data Fetch Succeeded", access your data like this:

 

api.data.<name of your DR that should return result>.<variable name that you have defined in your output schema in DR record>

 

as an example:

 

const clientData = api.data.getClinetDataFromApi.result;

console.log('clientData', clientData);

 

// transform your data

 

If my answer helped you in any way, please then mark it as helpful or correct. This will help others finding a solution.