Portal: Need to update all widgets on a page based on a change to an sn-record-picker in the header

John Tomko
Tera Expert

I am building a portal where the user needs to select an account (customer_account) via an sn-record-picker.  When an account is selected, I am setting a user session variable using putClientData and setting a user preference using savePreference.

 

All of this is working great and I've confirmed that the session and preference are getting updated.  However, there are several other widgets on the page which source data from the selected account that need to be refreshed when a different account is selected.  This is easy enough when the user goes to a new page, but how do I tell widgets on the current page to refresh?  

 

It seems like the ideal solution would be to add a watcher to the widgets' client scripts (akin to spUtil.recordWatch), but there really isn't a record to watch (unless I can get it to catch the new sys_user_preference entry).

 

The only other option I can think of is to wait for the server update to finish on my account selector widget, and somehow trigger a page refresh.  But I can't find a good way to do that on the server side.

 

For what it's worth, the account picker widget lives in the portal header. 

 

Any thoughts?

1 ACCEPTED SOLUTION

Hi @John Tomko,

 

Are these widgets (the ones that need to be refreshed) OOB or customized?

If the latter, you should be able to use events in the widgets - https://developer.servicenow.com/dev.do#!/learn/courses/utah/app_store_learnv2_serviceportal_utah_se...

 

Cheers

View solution in original post

3 REPLIES 3

John Tomko
Tera Expert

For now, I am handling it by reloading the page from the client script after the server updates, but that feels kinda cheesy.  I don't like making the page blink...

Hi @John Tomko,

 

Are these widgets (the ones that need to be refreshed) OOB or customized?

If the latter, you should be able to use events in the widgets - https://developer.servicenow.com/dev.do#!/learn/courses/utah/app_store_learnv2_serviceportal_utah_se...

 

Cheers

John Tomko
Tera Expert

Fantastic James!  Sorry it took so long to acknowledge, but I'd already decided to live with my page refresh - right up to the point where I needed to do something similar and really didn't want to refresh.