Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

How to pass data from one widget to another widget? Any example will of great help

SandeepKSingh
Kilo Sage
 
2 ACCEPTED SOLUTIONS

dgarad
Tera Sage

Hi @SandeepKSingh 

Refer the below link.

https://www.servicenow.com/community/developer-forum/how-to-communicate-between-two-widget/m-p/16344...

If my answer finds you well, helpful, and related to the question asked. Please mark it as correct and helpful.

Thanks
dgarad

View solution in original post

Ravi Gaurav
Giga Sage

Hi @SandeepKSingh 

 

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'
});

--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

 YouTube: https://www.youtube.com/@learnservicenowwithravi
 LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/

View solution in original post

2 REPLIES 2

dgarad
Tera Sage

Hi @SandeepKSingh 

Refer the below link.

https://www.servicenow.com/community/developer-forum/how-to-communicate-between-two-widget/m-p/16344...

If my answer finds you well, helpful, and related to the question asked. Please mark it as correct and helpful.

Thanks
dgarad

Ravi Gaurav
Giga Sage

Hi @SandeepKSingh 

 

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'
});

--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

 YouTube: https://www.youtube.com/@learnservicenowwithravi
 LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/