# How to apply a generic array comparison expression binding

**URL:** <https://forum.inductiveautomation.com/t/how-to-apply-a-generic-array-comparison-expression-binding/107115>\
**Category:** Ignition\
**Tags:** scripting, ignition81, perspective\
**Created:** [June 5, 2025, 10:56pm UTC](https://forum.inductiveautomation.com/t/how-to-apply-a-generic-array-comparison-expression-binding/107115 "2025-06-05T22:56:27Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![hoshito](https://avatars.discourse-cdn.com/v4/letter/h/ce73a5/32.png) [@hoshito](https://forum.inductiveautomation.com/u/hoshito)\
**Post date:** [June 5, 2025, 10:56pm UTC](https://forum.inductiveautomation.com/t/how-to-apply-a-generic-array-comparison-expression-binding/107115/1 "2025-06-05T22:56:27Z")

</div>

I'm trying to create an expression binding where compares the text in '.label' from an array equals a certain string it changes the color of the object binding.

It works fine if I define an array number, but I want to dynamically apply it to all events in the array as items are deleted and added to the array structure.

Example:  
`IF({this.props.scheduledEvents[0].label} = "TEST", '#6ECEB2', '#FFBE9F')`

Is there a way to do what I am trying to achieve?

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [June 5, 2025, 11:00pm UTC](https://forum.inductiveautomation.com/t/how-to-apply-a-generic-array-comparison-expression-binding/107115/2 "2025-06-05T23:00:24Z")

</div>

There is no iteration in base Ignition expressions. The [Integration Toolkit](https://forum.inductiveautomation.com/t/automation-professionals-integration-toolkit-module/74934) (free) from pturmel adds this capability.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 5, 2025, 11:21pm UTC](https://forum.inductiveautomation.com/t/how-to-apply-a-generic-array-comparison-expression-binding/107115/3 "2025-06-05T23:21:10Z")

</div>

Would a [Map Transform | Ignition User Manual](https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/working-with-perspective-components/bindings-in-perspective/transforms/map-transform) do what you want?

 ![2019-06-05_14-14-51-20b4d41acce7c3f15834a5c096a155ce](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/8/58f0a41563d5e26a0107738880b0f4031580924c.png)

In your case set the Input Type: Value and Output Type: Color. Enter the strings you're testing for in the values column.

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [June 6, 2025, 1:14am UTC](https://forum.inductiveautomation.com/t/how-to-apply-a-generic-array-comparison-expression-binding/107115/4 "2025-06-06T01:14:39Z")

</div>

> [@hoshito](#):
>
> all events in the array as items are deleted and added to the array structure.

How are you displaying all these events? Flex repeater? If you can, show us an example of how your view is set up.

> [@hoshito](#):
>
> IF({this.props.scheduledEvents[0].label} = "TEST", '#6ECEB2', '#FFBE9F')

Is this binding on the root container? or the base view?

---

<div class="post-metadata">

**Author:** ![hoshito](https://avatars.discourse-cdn.com/v4/letter/h/ce73a5/32.png) [@hoshito](https://forum.inductiveautomation.com/u/hoshito)\
**Post date:** [June 6, 2025, 1:46am UTC](https://forum.inductiveautomation.com/t/how-to-apply-a-generic-array-comparison-expression-binding/107115/5 "2025-06-06T01:46:54Z")

</div>

> [@ryan.white](#):
>
> How are you displaying all these events? Flex repeater? If you can, show us an example of how your view is set up.

The events are being displayed on a EquipmentSchedule component.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/0/b08150cc1f5b1bc37f0d37eb0343f9ec2b44a532.png)

> [@ryan.white](#):
>
> Is this binding on the root container? or the base view?

This binding is on the root container.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/5/05f2657107fdbadfe4adefd0f4f818fca3b602cb.png)

---

<div class="post-metadata">

**Author:** ![hoshito](https://avatars.discourse-cdn.com/v4/letter/h/ce73a5/32.png) [@hoshito](https://forum.inductiveautomation.com/u/hoshito)\
**Post date:** [June 6, 2025, 6:10am UTC](https://forum.inductiveautomation.com/t/how-to-apply-a-generic-array-comparison-expression-binding/107115/6 "2025-06-06T06:10:55Z")

</div>

Hi Everyone,

I worked out how to implement this.

I added a transform script on the 'props.scheduledEvents' of the Equipment Schedule component binding itself.

**Process:**

1. Loop over each event.
2. Copy it (`dict(e)`).
3. If `.label == "TEST"`, set `["color"] = "#6ECEB2"`; otherwise, set a default.
4. Append the copy to a new list.

- **Output:** Return the new list. Each event now has its own `"color"`.
- **Outcome:** The component (e.g. the Schedule) automatically consumes that `"color"` field to render events with the correct hex code.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/6/e631ed7d3c721c3f13ef3cc284096bbc0b315f04.png)

```python
def transform(self, value, quality, timestamp):
	# Transform script for property binding. Assume "value" is the incoming array of event‐objects.
	events = value # e.g. [{ "itemId":1, "eventId":16, "label":"TEST", ... }, {...}, ...]
	
	# We'll produce a new list, so that each event gets a "color" attribute based on its label.
	out = []
	
	for e in events:
	    # Make a shallow copy so we do not overwrite the original
	    newEvent = dict(e)  
	
	    if newEvent.get('label') == "TEST":
	        newEvent['backgroundColor'] = "#6ECEB2"
	    else:
	        # either leave it blank or give it a default color
	        newEvent['backgroundColor'] = "#FFBE9F"
	
	    out.append(newEvent)
	
	return out

```

Hope this help's anyone else.

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [June 6, 2025, 3:50pm UTC](https://forum.inductiveautomation.com/t/how-to-apply-a-generic-array-comparison-expression-binding/107115/7 "2025-06-06T15:50:14Z")

</div>

Likely unimportant performance consideration: You don't need to worry about making a copy of the original list, you can edit the original without concern. Nothing else is touching or using the original list.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [June 6, 2025, 3:50pm UTC](https://forum.inductiveautomation.com/t/how-to-apply-a-generic-array-comparison-expression-binding/107115/8 "2025-06-06T15:50:51Z")

</div>

I'll suggest this:

```python
color_map = {
	'TEST': '#6ECEB2',
	'FOO': '#AAFFEE',
	'BAR': '#443322'
}
default_color = '#FFBE9F'
return [
	dict(
		event,
		backgroundColor = color_map.get(event['label'], default_color]
	) for event in value
]

```

Simply configure your label -\> color map, and pick a default color.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [June 6, 2025, 3:52pm UTC](https://forum.inductiveautomation.com/t/how-to-apply-a-generic-array-comparison-expression-binding/107115/9 "2025-06-06T15:52:11Z")

</div>

Depending on the source of the data, the `e` might be immutable, in which case he does need to build a new dict to be able to add the `backgroundColor` key.

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [June 6, 2025, 3:53pm UTC](https://forum.inductiveautomation.com/t/how-to-apply-a-generic-array-comparison-expression-binding/107115/10 "2025-06-06T15:53:18Z")

</div>

> [@pascal.fragnoud](#):
>
> `e` might be immutable

Good point

> [@pascal.fragnoud](#):
>
> color map

Consider, having the color map as a separate custom property, and reference that from the script transform. Much more visible and you don't have to edit the script transform to make small tweaks or add items

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [June 6, 2025, 3:54pm UTC](https://forum.inductiveautomation.com/t/how-to-apply-a-generic-array-comparison-expression-binding/107115/11 "2025-06-06T15:54:39Z")

</div>

Yes that's not a bad idea.  
Could be used to make the color map dynamic.  
It also allows other properties to use the same colors.  
But then he should use a structure binding, to bind on both the original data and the color map.

If it doesn't change much, and it's only used by that transform, I'd stick to a simple color map in the script.

---

<div class="post-metadata">

**Author:** ![michaeelphillips](https://avatars.discourse-cdn.com/v4/letter/m/cc9497/32.png) [@michaeelphillips](https://forum.inductiveautomation.com/u/michaeelphillips)\
**Post date:** [June 6, 2025, 6:53pm UTC](https://forum.inductiveautomation.com/t/how-to-apply-a-generic-array-comparison-expression-binding/107115/12 "2025-06-06T18:53:32Z")

</div>

Expression bindings don’t support looping through arrays directly. You’ll need to handle the comparison logic outside the binding, like in a script or preprocessing step, then bind to a property that stores the result.
