Binding through scripting

I have a flex repeater with buttons in it. When clicking on a button i need its action to write to a parameter on the window the flex repeater is in. I understand i can do a binding on the parameters on the repeater with the params being writing in and out of the repeater from the embedded view. The problem is that the instances in the repeater are generated by code on the startup script because if clicked on job 1 on the previous screen, it will have different buttons displayed on the opening screen. So i need a way to apply bindings to the parameters for the flex repeater during the startup script.

Any suggestions?

When you copy and paste a binding, you can paste in into a text editor.

{
  "type": "property",
  "config": {
    "bidirectional": true,
    "path": "view.params.unitID"
  }
}

So through scripting how would you apply this to a property?

If you make it = that, then it sees it as an object with dictionaries in it.

I don’t think dynamically applying bindings is the right solution. Why not have the buttons fire a page-level message, with the sendMessage function?

1 Like

I liked into that and maybe I just didn’t quite understand that function. So the repeater is in a view (a main view) and I have a parameter called unitID. So would I use system.perspective.sendMessage(messageType, payload={“unitID” : value }, “page”) in the actionPerformed script in the button?
What would be for messageType?

messageType can be whatever you want it to be - it just has to match the messageType on whatever message handler(s) you have created. It should be unique enough that you don’t have them overlap.

A couple of notes about using the function:

  1. unless you’ve already defined a messageType variable, then the argument expects a str type (“UPDATEUNITID” in my example, or any unique string value you want to use).
  2. You need to include the keyword for scope since you supplied the keyword for payload (python quirk/rule).
system.perspective.sendMessage("UPDATEUNITID", payload={“unitID” : value }, scope=“page”)

Then configure a component to listen for the message:

  1. Right-click a component.
  2. Select “Configure Scripts”.
  3. Double-click “+ Add handler”.
  4. Set the Message Type input to “UPDATEUNITID”.
  5. Unselect the “Session” checkbox.
  6. Select the “Page” checkbox.
  7. Supply a script which performs some action with the payload.

To access your value from the payload, you’ll want to use payload['unitID'].

I got it working as expected. Thanks guys, i had to use the sendMessage function to get it working.

1 Like