Script Adapter

You can use a Script Adapter widget to map event data from one format into another between two widgets.

The Script Adapter widget is wired between two other widgets so that it can perform a data transformation on the event payload. Using this widget, you can:

  • Display event data to help you debug your widgets
  • Insert logic in between widget event communication; for example, to map events of one format to another.

When wiring widgets, if the widgets have the same event and the format for the event data is the same, you can simply wire one widget to another. However, if the format for the event data is not the same, you will need to transform the data in the source event into a format expected by the target widget. The Script Adapter widget is the way you achieve this transformation. When the Script Adapter widget receives an event from a widget it is wired to, it displays the event details in the Received Event section. The Script Adapter then runs a script that transforms the data as a function with a "payload" parameter, which is the payload of the incoming event. The script is how you manipulate the payload using any type of logic that you feel is necessary. The value that your custom code returns is the payload of the outbound event of this widget. The Sent Event section displays this information.

For example, a Script Adapter receives a wired event with a payload of "test data", which the Received Event section displays. The Script Adapter has the following script:

alert("The value of the payload is: " + payload);
return "Event Payload: " + payload + "!";

The Sent Event section displays "Event Payload: test data!" as the payload for the outbound event.