issue with \$rootscope \$broadcast
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2017 08:22 AM
Hi Everyone, I'm trying to use $rootscope.$broadcast to communicate between two widgets, but can't seem to get it to work 100%. We're using the out of the box fed-form-new widget and have added a piece of code that fires off an event letting other widgets know a new record has been added:
$scope.$on("spModel.uiActionComplete", function(evt, response) {
var sysID = (response.isInsert) ? response.sys_id : $scope.data.sys_id;
loadForm($scope.data.table, sysID).then(constructResponseHandler(response));
if (response.isInsert) {
if ($scope.data.table == 'sn_hr_core_beneficiary') {
$rootScope.$broadcast('recordAdded', $scope.data.table);
}
}
});
We've also created a My Contacts widget, which opens up a modal widow of fed-form-new. When a user completes the form and submits, we want the widget to update with the new record without a user needing to press refresh on the browser:
$rootScope.$on('recordAdded', function(event,data) {
$timeout(function() {
if (data == 'sn_hr_core_beneficiary') {
$scope.server.update();
}
})
})
We can't seem to get this to work properly, is there something wrong in the code?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2017 08:57 AM
Hi David,
Use server.update
For your second query:we want the widget to update with the new record without a user needing to press refresh on the browser:
Check this : Widget scripting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2017 09:09 AM
Hi Midhun, I already have $scope.server.update(); in the My Contacts widget. Isn't that the same thing? Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2017 09:42 AM
replace $rootScope.$broadcast with $rootScope.$emit
also make sure you have added $rootScope to client controller parameters.
(please mark helpful/like/correct if it helps)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2017 02:10 PM
Hi Rushit,
I tried that and it still doesn't work. Thanks.