how to call a widget from catalog client script and pass the data of a variable in servicenow

Community Alums
Not applicable

how to call a widget from catalog client script and pass the data of a variable in servicenow

1 REPLY 1

ChrisBurks
Mega Sage

Hi Awais,

Is the widget embedded as a variable on the catalog item?

If so, you can listen for the change of that variable value within the widget itself by the following code:

// in client controller
api.controller = function($scope, $rootScope){

 var c = this;

 $rootScope.$on('field.change', function(evt, vdata){
		console.log("VDATA: ", vdata)
            //either evt or vdata should contain information that you need to make sure that the script 
           // only does something when it's the correct variable
           // For example
          if (vdata.field.name == 'my_variable'){
                   //do something here
          }
			
  })

}

The above will watch for field changes (inputs) when they get populated or values change. It also contains both oldValue and newValue in case you need to keep track.