UI Builder: Reload a page

Hasan6
ServiceNow Employee
ServiceNow Employee

Hi Community,

I have a ui builder page, and want to create a button which, upon click, executes an action and then reloads the page.

While I can get the 'executes and action' part done through the event scripts, I am not able to reload the page.

Any suggestions on how to achieve this?

1 ACCEPTED SOLUTION

Akshay_Jain22
ServiceNow Employee
ServiceNow Employee

Hi @Hasan6 

Though I would not personally recommend this method to update the data on the Page, as it can be refreshed through the definition of client states and data resources defined with dynamic inputs and event handler-triggers. 

You can use the below script in order to reload the page by binding any event with the below client script -

 

Screenshot 2024-08-18 at 10.42.31 PM.png

 

Please note that you can access the document object using this code for other use cases as well. 

Checkout full blog on this for more information on Pros and Cons.

View solution in original post

15 REPLIES 15

Hasan6
ServiceNow Employee
ServiceNow Employee

Getting "'location' is not defined." error.

Same problem! Did you ever manage to solve this? 

location.reload(true); is the same as window.location.reload(true); So that was already tested 😉


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

Akshay_Jain22
ServiceNow Employee
ServiceNow Employee

Hi @Hasan6 

Though I would not personally recommend this method to update the data on the Page, as it can be refreshed through the definition of client states and data resources defined with dynamic inputs and event handler-triggers. 

You can use the below script in order to reload the page by binding any event with the below client script -

 

Screenshot 2024-08-18 at 10.42.31 PM.png

 

Please note that you can access the document object using this code for other use cases as well. 

Checkout full blog on this for more information on Pros and Cons.

Hi @Akshay_Jain22 ,

I've been looking for this everywhere for the last few days! This method worked. Thank you so much!