# Binding through scripting

**URL:** <https://forum.inductiveautomation.com/t/binding-through-scripting/27206>\
**Category:** Ignition Early Access\
**Tags:** ignition80\
**Created:** [August 6, 2019, 8:32pm UTC](https://forum.inductiveautomation.com/t/binding-through-scripting/27206 "2019-08-06T20:32:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jramirez3](https://avatars.discourse-cdn.com/v4/letter/j/a183cd/32.png) [@jramirez3](https://forum.inductiveautomation.com/u/jramirez3)\
**Post date:** [August 6, 2019, 8:32pm UTC](https://forum.inductiveautomation.com/t/binding-through-scripting/27206/1 "2019-08-06T20:32:03Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jramirez3](https://avatars.discourse-cdn.com/v4/letter/j/a183cd/32.png) [@jramirez3](https://forum.inductiveautomation.com/u/jramirez3)\
**Post date:** [August 6, 2019, 9:53pm UTC](https://forum.inductiveautomation.com/t/binding-through-scripting/27206/2 "2019-08-06T21:53:50Z")

</div>

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

```auto
{
  "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.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [August 6, 2019, 10:06pm UTC](https://forum.inductiveautomation.com/t/binding-through-scripting/27206/3 "2019-08-06T22:06:41Z")

</div>

I don’t think dynamically applying bindings is the right solution. Why not have the buttons fire a page-level message, with the [sendMessage](https://docs.inductiveautomation.com/display/DOC80/Component+Message+Handlers) function?

---

<div class="post-metadata">

**Author:** ![jramirez3](https://avatars.discourse-cdn.com/v4/letter/j/a183cd/32.png) [@jramirez3](https://forum.inductiveautomation.com/u/jramirez3)\
**Post date:** [August 6, 2019, 10:17pm UTC](https://forum.inductiveautomation.com/t/binding-through-scripting/27206/4 "2019-08-06T22:17:45Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [August 6, 2019, 10:19pm UTC](https://forum.inductiveautomation.com/t/binding-through-scripting/27206/5 "2019-08-06T22:19:27Z")

</div>

`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.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [August 6, 2019, 10:40pm UTC](https://forum.inductiveautomation.com/t/binding-through-scripting/27206/6 "2019-08-06T22:40:48Z")

</div>

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).

```auto
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']`.

---

<div class="post-metadata">

**Author:** ![jramirez3](https://avatars.discourse-cdn.com/v4/letter/j/a183cd/32.png) [@jramirez3](https://forum.inductiveautomation.com/u/jramirez3)\
**Post date:** [August 7, 2019, 7:55pm UTC](https://forum.inductiveautomation.com/t/binding-through-scripting/27206/7 "2019-08-07T19:55:43Z")

</div>

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