- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-26-2022 03:16 PM
Hi all,
I am working in UI Builder, trying to set up a client script to set the visibility of a few buttons on the form. I have my client script bound to the "Page Ready" event on the page so it will behave similarly to an onLoad client script in the traditional platform UI. I want to make a button become visible if the user logged in is the user that the record is assigned to.
I am in the process of setting up a client script to check some data and determine if the user should see the button, but the script will not run on the "Page Ready" event. My client script is as follows:
The script does not log anything to the console when the page loads. I have this same script bound to a button, and when the page is not in the process of loading and I click the button, it logs the data to the console properly.
I have also set up a second client script just to test the Page Ready event, as follows:
I have this script bound to the Page Ready event as well and this one does work as expected, where it logs "hello is this on" to the console twice when the page loads. So it seems that maybe the look up record data is not available yet when the page is loading. But then how can I make the buttons visible or not visible depending on data when the page loads? Any advice would be much appreciated, thanks!
Solved! Go to Solution.
- Labels:
-
Now Experience UI Framework

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-27-2022 01:41 PM
It sounds like the data isn't ready at page load. You could instead run this script on the data resource executed successfully (I don't think it's actually called that) event that fires when the data resource executes so you can be sure that the data has come back.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-26-2022 04:00 PM
can you do a and see if you get anything.
console.log(JSON.stringify(api.data));
Vinod Kumar Kachineni
Community Rising Star 2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-26-2022 04:42 PM
Hi,
Thanks for the suggestion. I tried this and got an empty object {} when running the script through the Page Ready event, as well as when running the script through a button.
Out of curiosity I also ran the script with
console.log(JSON.stringify(api));
and it returned an object that had a property called data, again with an empty object {}. It looked something like this:
console.log(JSON.stringify(api));
{
'viewports' : ...,
'context': ...,
'user': ...,
'data': {},
}
Interestingly, the "state" section of the api also only showed one of my two client state parameters. I'm not sure if that's relevant but it's something I noticed.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-27-2022 01:41 PM
It sounds like the data isn't ready at page load. You could instead run this script on the data resource executed successfully (I don't think it's actually called that) event that fires when the data resource executes so you can be sure that the data has come back.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-03-2022 02:42 PM
We were able to get our requirement completed this way. I didn't realize that there was an event that fired when the data resource has finished executing but that was exactly what we were looking for. Thanks!