- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2024 10:44 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2024 10:46 PM
Hi Sandeep,
Please refer this community link
https://www.servicenow.com/community/developer-blog/how-to-communicate-between-widgets-in-service-po...
Best Regards,
Ramesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2024 10:57 PM
Hi @SandeepKSingh
You can follow the below:-
We can use $emit, $broadcast and $on to send and recieve the data.
- Example by using $broadcast
Include below code in client controller on source widget to send data.
$rootScope.$broadcast('dataEvent', data);
Include below code in client controller on target widget to recieve data.
$scope.$on('dataEvent', function (event, data) {
console.log(data); // 'recieved data'
});
- Example by using $emit
Include below code in client controller on source widget to send data.
$rootScope.$emit('dataEvent', id);
Include below code in client controller on target widget to recieve data.
$scope.$on('dataEvent', function (event, data) {
console.log(data); // 'recieved data'
});
Note : According to ServiceNow San diego docs, Avoid the use of $rootScope.$broadcast() because it can cause performance issues. Reference link - Using AngularJS Events with Widgets
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2024 10:46 PM
Hi Sandeep,
Please refer this community link
https://www.servicenow.com/community/developer-blog/how-to-communicate-between-widgets-in-service-po...
Best Regards,
Ramesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2024 10:57 PM
Hi @SandeepKSingh
You can follow the below:-
We can use $emit, $broadcast and $on to send and recieve the data.
- Example by using $broadcast
Include below code in client controller on source widget to send data.
$rootScope.$broadcast('dataEvent', data);
Include below code in client controller on target widget to recieve data.
$scope.$on('dataEvent', function (event, data) {
console.log(data); // 'recieved data'
});
- Example by using $emit
Include below code in client controller on source widget to send data.
$rootScope.$emit('dataEvent', id);
Include below code in client controller on target widget to recieve data.
$scope.$on('dataEvent', function (event, data) {
console.log(data); // 'recieved data'
});
Note : According to ServiceNow San diego docs, Avoid the use of $rootScope.$broadcast() because it can cause performance issues. Reference link - Using AngularJS Events with Widgets