Inter-Widget Communication

In some cases where an extension has multiple widgets, communication between each widget becomes crucial. This is made possible through inter-widget communication.

For Example:Let us say an extension has two widgets: one at desk.ticket.detail.rightpanel and the other at desk.ticket.detail.subtab. Data from the widget on the right panel needs to be sent to the widget on the subtab. This requirement is achieved through the given code snippet:

AttributeDescription
App.instance.getWidgets()Returns the array of sibling widgets of the extension.
siblingwidgetId = widgets[0].widgetIDGets the ID of the widget on the subtab. Widgets will have only one element. Therefore, the iteration is not required.
var siblingWidget = App.instance.getWidgetInstance(siblingwidgetId)  Returns the whole instance of the widget on the subtab.
siblingWidget.emit('event', {from : Math.random()})Sends the event response with data to the widget on the subtab.

Sample Request

Copied//Event Emit Sample Code
App.instance.getWidgets().then(function(widgets)
{
//get the Id of widget we want to communicate
siblingwidgetId = widgets[0].widgetID;
//get the instance of widget by widgetId
var siblingWidget = App.instance.getWidgetInstance(siblingwidgetId);
//data to send to sibling widget
 pi_data = {
  name: "Jhon",
  age: 25
  }
//sending data to sibling widget
 siblingWidget.emit('event', pi_data);
});

 

 

To enable the widget on the subtab to receive the event sent from the widget on the right panel, use the following code snippet

Sample Request

Copied// Event Listener Sample Code

App.instance.on('event', function(data){
/* data from other widget will be in "data" */
console.log("from Widget 2", data);
});