How to call the data resource from Client Scripts UI Builder

mohammedghouse
Giga Guru
Hello All,
I have define the state parameter "atternityLink" its type is string and have given initial value to that link. 
Below is the client script where I am trying to set the state value but not working. But everytime I am getting the same value which I have provided as initial value.
const
 userId = api.data.caller_info.result.user_name.value;
    const ciName =  api.data.device_info.results.name.value;
    urlLink = "URLSTRING1" + ciName+ "URLSTRING2" + userId +"URLSTRING3"
    api.setState("atternityLink",urlLink)
 
data.caller_info.result & api.data.device_info.results are local data resources . 

Thanks 
Mohammed Ghouse

9 REPLIES 9

Anil Lande
Kilo Patron

Hi,

In order to execute your client script you to trigger it through an event.

Can you please explain the use case?

When your state value should change? is there any activity happening on your page that can be used to trigger event though respective component.

 

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Hello @Anil Lande , 

I am trying to create external URL based on user_name and CI details, So I used the component called Text Link, I tried below multiple ways to achieve but not working. 

 

1) In Link (Edit scripted property value and return the URL) I try to create the URL dynamically (URLSTRING1" + api.data.device_info.results.name.value "URLSTRING2" + api.data.caller_info.result.user_name.value +"URLSTRING3") trying to get the data from local data resource. 

2) After the above method didn't work (I tried using Event handler),  Triggering Client Script which set the client State. After that triggering Link to Destination Event Handler in external url field binding the state value. 

 

mohammedghouse_0-1702279467362.pngmohammedghouse_1-1702279585633.png


I am new to UI Builder and not sure I am doing in right way. 


Thanks 

Mohammed Ghouse

 

Hi @mohammedghouse ,

Can you please elaborate how did you get the client script triggered, i.e. where and when did you set the value to that state. Setting the value to state in UI Builder is an "asynchronous" process, it's similar to React / Vue state management.

Hi,

First try sending hardcoded values through Client state variable.

If you are able to get the static link then try to make it dynamic based on 1 value and similar way you can go for additional inputs.

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

@mohammedghouse ,

 

Agree with Anil here. I would also generate log to see whether url path is correct.