how to call a widget from catalog client script and pass the data of a variable in servicenow
Community Alums
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2022 04:12 AM
how to call a widget from catalog client script and pass the data of a variable in servicenow
Labels:
- Labels:
-
Service Portal Development
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2022 04:40 AM
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.