Catalog Client script - broadcast event to widget

erantal2000
Giga Contributor

Hello everyone,

I have a record producer that I incorporated in Service portal.

One of the variables in the record producer is a widget.

What I am trying to do is communicate between catalog client script and the widget. What I want to achieve is when one of the variables change, I will do some manipulation in the widget controls. For this purpose I want to broadcast an event to the widget, just like you interact between 2 widgets.

But I can't seem to find a way to do it. There is no apparent way to communicate between the catalog client script and the widget.

Does anyone know how I can achieve this?

 

Thanks

1 ACCEPTED SOLUTION

Thomas Wright-1
Mega Expert

Probably a bit late for you, but this one is actually pretty simple.

You don't need to broadcast from a client script, you can have a widget react on a variable change using $watch:

$scope.$watch(function () {    
	return $scope.page.g_form.getValue('my_variable');    
}, function (value) {
	//Do stuff with value
}

I don't think it's possible to broadcast from catalog client scripts as $rootscope is not defined, but you should be able to handle any events needed with a $watch in this way, even if it is just by setting a hidden variable which is specifically being watched by your widget.

View solution in original post

3 REPLIES 3

Thomas Wright-1
Mega Expert

Probably a bit late for you, but this one is actually pretty simple.

You don't need to broadcast from a client script, you can have a widget react on a variable change using $watch:

$scope.$watch(function () {    
	return $scope.page.g_form.getValue('my_variable');    
}, function (value) {
	//Do stuff with value
}

I don't think it's possible to broadcast from catalog client scripts as $rootscope is not defined, but you should be able to handle any events needed with a $watch in this way, even if it is just by setting a hidden variable which is specifically being watched by your widget.

Is anyone still following this thread? Im trying to do this in a catalog item widget and the console fills with errors.

js_includes_sp_libs.jsx?v=06-23-2023_1740&lp=Fri_Jul_28_06_14_53_PDT_2023&c=30_878:142 TypeError: Cannot read properties of undefined (reading 'getValue')

erantal2000
Giga Contributor

We have a winner.

Not late at all.

Amazing.

Thanks!