# Custom property binding with null subscript value fetches first value of referenced array

**URL:** <https://forum.inductiveautomation.com/t/custom-property-binding-with-null-subscript-value-fetches-first-value-of-referenced-array/77778>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [August 11, 2023, 11:46pm UTC](https://forum.inductiveautomation.com/t/custom-property-binding-with-null-subscript-value-fetches-first-value-of-referenced-array/77778 "2023-08-11T23:46:16Z")\
**Posts on this page:** 4\
**Page:** 1

<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:** [August 11, 2023, 11:46pm UTC](https://forum.inductiveautomation.com/t/custom-property-binding-with-null-subscript-value-fetches-first-value-of-referenced-array/77778/1 "2023-08-11T23:46:16Z")

</div>

I am unsure if this is intended behavior or not. Ignition version 8.1.25

I have an expression binding on a custom property in perspective that is along the lines of  
`{session.custom.array1}[{session.custom.selection1}] `.

I set `selection1` to null when initializing but also when a different selection field is modified. `selection1` is a selection index, so I use null since setting to a negative number would result in it grabbing something else from the array.

When populating `array1` after changing selections elsewhere, and not changing the value in `selection1` from null, the custom property with the above binding has the data from the first item of `array1`.

I then tested directly with a binding of `{session.custom.array1}[null]` and it returned the data from the first item in `array1`

> **Array and bound properties**
>
> ![tmp1](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/a/3ad8f609d7d4aa9cbedb368b3245011401588467.png)
> 
> ![tmp2](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/1/b120c24e7a3d710490fe8c6ebb9286f88b732696.png)
> 
> ![tmp3](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/d/ade1e99eaa0b48580adc4b54efb98718df8d9249.png)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [August 11, 2023, 11:52pm UTC](https://forum.inductiveautomation.com/t/custom-property-binding-with-null-subscript-value-fetches-first-value-of-referenced-array/77778/2 "2023-08-11T23:52:23Z")

</div>

Sounds like null is being coerced to zero. Not sure what it should be.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [August 11, 2023, 11:55pm UTC](https://forum.inductiveautomation.com/t/custom-property-binding-with-null-subscript-value-fetches-first-value-of-referenced-array/77778/3 "2023-08-11T23:55:19Z")

</div>

> [@ryan.white](#):
>
> I set `selection1` to null when initializing but also when a different selection field is modified. `selection1` is a selection index, so I use null since setting to a negative number would result in it grabbing something else from the array.

In python, yes `someList[-1]` would indeed retrieve the last item in the list. Not so in the expression language. The expression language does not allow negative indexes. You would get and `Error_ExpressionEval: Error performing subscript operation`. Maybe that's acceptable maybe not.

Not sure what it should be, but you can probably come up with some combination of expressions to return an acceptable value.

---

<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:** [August 11, 2023, 11:58pm UTC](https://forum.inductiveautomation.com/t/custom-property-binding-with-null-subscript-value-fetches-first-value-of-referenced-array/77778/4 "2023-08-11T23:58:04Z")

</div>

> [@pturmel](#):
>
> Sounds like null is being coerced to zero. Not sure what it should be.

That's what it seems like. Caught me off guard because I figured it would return null.

> [@lrose](#):
>
> Not sure what it should be, but you can probably come up with some combination of expressions to return an acceptable value.

I've thrown in a `isNull` check before the subscript operation, and have it return a blank value if so. I just wasn't sure if this was intended behavior or what.
