Read control nodes and update widget properties

This example explains how to read control nodes, concat strings, and update a widget’s text property.

Functions covered

  • comp.findWidget()

  • comp.getPayload()

  • widget.setPayload()

Load this example composition to follow along in a real composition.

Composition structure

The example composition has one sub-composition called Lower, as you can see in the composition tree.

To see this sub-composition's widgets:

  1. Open the composition script editor within the same example composition as above select the Lower composition script.

  2. In the composition navigator, select the Widget Explorer tab.

This composition contains three widgets, but for this quick start, you'll look at its text widget, which in the composition is called lowerFullname.

Composition script

Now that you have located the composition's widgets, learn how to read their assigned control nodes and update them by reading the comments in the Lower composition script.

You can also copy and paste the composition script below into your own compositions.

Lower Script
(function() {
  return {

    init: function(comp, context) {

      // get reference to the fullname widget
      const wiLowerFullname = comp.findWidget("lowerFullname")[0];

      // get control node payload as JSON object
      const p = comp.getPayload2();
      console.log(p);

      // concat control node content and change the lastname to upper case.
      const fullname = `${p["Firstname"]} ${p["Lastname"].toUpperCase()}`;

      // update fullname text
      wiLowerFullname.setPayload({
        "text": fullname
      });

    },

    close: function(comp, context) {}
  };
})();

Last updated