Service Portal widgets communication

dianemiro
Kilo Sage

Hello Everyone,

 

We have a requirement to optimize a page in Service Portal. Currently, all widgets are performing the same queries but each of the widget are performing gliderecord in the Server Script. We want to have the gliderecord in only 1 widget (Widget 1) and call or use the data from Widget 1 to use it on other Widgets (Widget 1, Widget 2, etc.).

 

Regards,
Diane

1 ACCEPTED SOLUTION

Hi @dianemiro,

 

Good point, I was investigating and found a different option:

 

Local Storage

 

This way in your first widget you can make the queries on the Server Side and use Local Storage as it gets saved on the user session and on the other widgets you can just use session.getClientData(object, param2), and all your data saved will be accessible. It solved a lot of performance issues in a particular use case that I had.

 

As per your question, broadcast does expect something to trigger an event so it can replicate data to another widget that is listening - but it can be tricky and you can maybe try this:

 

Angular run function on broadcast and page load

 

View solution in original post

5 REPLIES 5

Marcos Kassak
Kilo Sage
Kilo Sage

Hi @dianemiro,

 

You can use these two angular methods:

 

$broadcast Method. A method of $rootScope that dispatches an event to all its child $scope.

 

$on Method. A method of $rootScope that listens to propagated events. It has two parameters: the name of the event to listen, to and the function to be executed.

 

A quick video to help: https://youtu.be/uEK0SWiiZ3E

 

Tip: Sometimes the call on the client side using Table API from ServiceNow was performing better for a use case that I had, so if you want to test it too it might be faster than calling in the server, pulling from the client, and only then showing at the browser.

 

If you found my answer helpful or correct in any way, please don't forget to mark it to help future readers! 👍

 

--

 

Kind regards,


Marcos Kassak
Solution Consultant  🎯

Hello @Marcos Kassak,

 

Thanks for your help! I watched the quick video and it involves having a button clicked to initiate the listeners. Does these methods also support without the need to click a button? Thank you!

Regards,

Diane Miro

Hi @dianemiro,

 

Good point, I was investigating and found a different option:

 

Local Storage

 

This way in your first widget you can make the queries on the Server Side and use Local Storage as it gets saved on the user session and on the other widgets you can just use session.getClientData(object, param2), and all your data saved will be accessible. It solved a lot of performance issues in a particular use case that I had.

 

As per your question, broadcast does expect something to trigger an event so it can replicate data to another widget that is listening - but it can be tricky and you can maybe try this:

 

Angular run function on broadcast and page load

 

Thank you, @Marcos Kassak, I think the local storage will be more applicable for our use case.

 

Regards,

Diane