Passing value from one widget to another in Service Portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2018 08:55 AM
Hi All,
I have written following client Controller scripts in two widgets to pass value which is not working:
1st instance to pass value
function($scope, spUtil, $rootScope) {
/* widget controller */
var c = this;
var selectedName = ''; //value which needs to be passed
setTimeout(function () {
var obj= {
value : selectedName
};
$rootScope.$broadcast('cent', obj);
alert("Selected value is: " + selectedName+" object value "+obj.value);
},1000);
}
2nd instance which receives the value
function($scope , $rootScope) {
var c = this;
$rootScope.$on('cent', function(event,obj) {
c.aLocation = obj.value;
alert("From Admin Option: " + c.aLocation);
c.server.update();
});
}
Where am doing wrong?
(is there any reference where I can read and understand the concept?)
Thanks
Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2018 09:01 AM
What exactly are you trying to do and when you say it's not working, what is actually happening? Is it throwing JS errors, not doing anything?
Here is a good reference and tutorial that includes passing an event from one widget to another: https://developer.servicenow.com/app.do#!/training/article/app_store_learnv2_serviceportal_kingston_...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2018 09:09 AM
I wrote a tutorial a while back about using Angular.js events to communication between widgets.
Hopefully, this is helpful: https://serviceportal.io/using-events-communicate-widgets/
Thanks,
Nathan Firth
Founder and ServiceNow Architect
NewRocket, Inc.
nathan.firth@newrocket.com
http://serviceportal.io
http://newrocket.com

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2018 10:14 AM
In my opinion you are better off using angular services to do this instead of using angular event model. Angular services are meant for this exact purpose (sharing data between controllers). I have a pretty simple example of using services on my share app here. The app itself has nothing to do with your use case, but it contains an example of using services to share data with controllers:
You can read more about angular services here. It will be worth your time to learn to use these:
https://docs.angularjs.org/guide/services
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2020 02:51 PM
Hey, check the youtube vidoe i made for pass data between 2 widgets https://www.youtube.com/watch?v=LooT596ZhtQ