Widget that reacts to onChange event of Variable

Geoffrey2
ServiceNow Employee
ServiceNow Employee

Hi. I am building a Catalog Item for use in the Service Portal.  I have a Widget that is embedded in the Catalog Item using a Macro type Variable. And I have another Reference type Variable on the Item. I want the Widget to respond when the Reference field is changed. It needs to look up and display information related to the Referenced record.

I have found about a million Community Articles, Blogs, and YouTube videos that explain how you can use $rootScope.$broadcast to communicate between Widgets. But I'm not trying to communicate between 2 Widgets. I need to communicate from an onChange Catalog Client Script to a Widget.  Or I need to add a listener to the Reference type Variable from my Widget. Or I need a different solution entirely. Does anybody know how to do this?

My workaround at the moment is to use a setInterval in the Widget that manually looks for a change in the Reference Variable using $scope.page.g_form.getValue('my_ref_field'). This solution works, but it sucks and I hate it.

6 REPLIES 6

Sudipta5
Tera Contributor

It worked perfectly for me. Thank you. 

My pleasure, glad it helped 😉