issue with \$rootscope \$broadcast

davilu
Mega Sage

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?

4 REPLIES 4

Midhun1
Giga Guru

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


Hi Midhun, I already have $scope.server.update(); in the My Contacts widget.   Isn't that the same thing?   Thanks!


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)


davilu
Mega Sage

Hi Rushit,



I tried that and it still doesn't work.   Thanks.