Communicate between two widget instances that are of the same widget?

JennyHu
Tera Guru
Tera Guru

Good morning!

I have two widget instances (say A, and B) on a page that are using the same Data Table widget, with different instance options to pull data from different table sources.

When a record is clicked in widget instance A, I would like to pass the sysID of the clicked record to widget instance B to filter dynamically based on the sysID.

My question is.. is it possible to broadcast/emit the event from widget instance A and listen for the event in widget instance B?   How can it be done since there is only one copy of the widget code?

My workaround to this is to clone the widget and customize the widget code a bit so that one widget broadcast, and the other widget listen.   Though, I don't know if this is a best practice since the function of the widget is pretty much the same.

I also thought about creating a wrapper widget and embedded Data Table widget A and B.. it seems more complicated.

Any suggestion is welcome!

Thanks,

Jenny

9 REPLIES 9

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hi Jenny,



You should be able to have the widget both broadcast and listen for events. Just like you are using the instance options to change the data source, you could use them to also determine which widget is broadcasting and which is listening.


Thanks Brad, I will give it a try.


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Jenny,



You may find the below blog helpful


How to communicate between widgets in Service Portal


Hi Pradeep,



Thank you for the response!   Yes, I have read through that blog and find it helpful.   It talks about communicating between two different widgets.   I was hoping to find example of communicating between two instances of the same widget.



Regards,


Jenny