# Instances of checkboxes failing on "selected" property

**URL:** <https://forum.inductiveautomation.com/t/instances-of-checkboxes-failing-on-selected-property/99969>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [December 18, 2024, 3:01am UTC](https://forum.inductiveautomation.com/t/instances-of-checkboxes-failing-on-selected-property/99969 "2024-12-18T03:01:37Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![pdixon](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pdixon/32/6899_2.png) [@pdixon](https://forum.inductiveautomation.com/u/pdixon)\
**Post date:** [December 18, 2024, 3:01am UTC](https://forum.inductiveautomation.com/t/instances-of-checkboxes-failing-on-selected-property/99969/1 "2024-12-18T03:01:37Z")

</div>

I have a Perspective view where the user can select from CheckBox instances in a flex repeater. After selecting from the list a button will submit the list of names that were selected. The code is below:

```python
	# step through the rows
	for instance in Instances:
		logger.info("Instance " + str(instance.text))	
		if instance.selected:
			Names.append(str(instance.text))
			logger.info("Name " + str(instance.text))				
	

```

If I choose as follows:

 ![ig_instancecheckboxselected_2024-12-17 at 8.52.28 PM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/2/c2ceea83b2572cd64a461e6b7a5e1bfc7a055391.jpeg)

i get an error at "if instance.selected:" stating that there is no "selected" attribute:

 ![ig_instancecheckboxselected_2024-12-17 at 8.50.30 PM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/d/fdf44b7e3fcde232b1762e623f5b8161388249e9.jpeg)

If I choose as follows:

 ![ig_instancecheckboxselected_2024-12-17 at 8.57.39 PM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/f/df024e058e9444f8b84a5a11ef56220ec4ae9ec5.jpeg)

the code executes as expected, sees that the "selected" attribute on the Jill instance exists but is false, and there is no error:

 ![ig_instancecheckboxselected_2024-12-17 at 8.57.26 PM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/3/f393e7ee8ecf00f092c7e2dab90dcda6c664f722.jpeg)

How do I fix this error?

---

<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:** [December 18, 2024, 4:03am UTC](https://forum.inductiveautomation.com/t/instances-of-checkboxes-failing-on-selected-property/99969/2 "2024-12-18T04:03:29Z")

</div>

~~Are you iterating over the instances prop in the flex repeater? Then your syntax would need to be~~

~~ 

```python
if instance['selected']:

```

 ~~

~~The perspective object gets a wrapper that makes it act sort of like a python dictionary, so you have to use python's syntax for accessing keys in a dict. (ie, `dict['key']`).~~

Double check the capitalization of your key/attribute(selected vs Selected), and check that `selected` actually exists in each instance. If you don't add that key when generating the instances to begin with, it will not be present.

~~As a one-liner:~~

~~ 

```python
names = [instance['text'] for instance in instances if instance['selected']]

```

 ~~

Side note, you can do

```python
logger.infof("Instance %s", str(instance['text']))

```

to take advantage of java's string formatting.

Edit: I'm so used to sanitizing perspective data objects I forgot you can do `object.attribute` on the wrapper class

---

<div class="post-metadata">

**Author:** ![pdixon](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pdixon/32/6899_2.png) [@pdixon](https://forum.inductiveautomation.com/u/pdixon)\
**Post date:** [December 18, 2024, 2:58pm UTC](https://forum.inductiveautomation.com/t/instances-of-checkboxes-failing-on-selected-property/99969/3 "2024-12-18T14:58:16Z")

</div>

I don't believe I am doing anything different in adding the last instance to the flex repeater than I am doing to the preceding instances. They should all have ".selected".

The CheckBox has params "selected" and "text"

 ![ig_instancecheckboxselected_detail_2024-12-18 at 8.45.08 AM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/5/659589d140a6a2251019d3f09304df94e5ad704c.jpeg)

They are bound to the Checkbox components of the same name:

 ![ig_instancecheckboxselected_detail_2024-12-18 at 8.45.33 AM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/6/a6c5a223f991be7bda397a53c383c3211fc46547.jpeg)

The instances of the CheckBox view show up and should all have the same params:

 ![ig_instancecheckboxselected_detail_2024-12-18 at 8.36.15 AM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/4/54d5be400eefd62578c822b33d37d09fbfe2ee66.jpeg)

---

<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:** [December 18, 2024, 3:17pm UTC](https://forum.inductiveautomation.com/t/instances-of-checkboxes-failing-on-selected-property/99969/4 "2024-12-18T15:17:30Z")

</div>

Observations after a quick scan:  
Your third screengrab (caption your images and give them numbers - it makes it much easier to talk about them) shows that each `instances` member has a `text` property but no `selected` property. That would explain the '_there is no "selected" attribute_' error message.

Also, you've cropped your first image too much on the right so we can't see if you've set the PARAMS as Input/Output type (set by cycling through the arrow options on the right edge of the Perspective Property Editor).

---

<div class="post-metadata">

**Author:** ![pdixon](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pdixon/32/6899_2.png) [@pdixon](https://forum.inductiveautomation.com/u/pdixon)\
**Post date:** [December 18, 2024, 3:26pm UTC](https://forum.inductiveautomation.com/t/instances-of-checkboxes-failing-on-selected-property/99969/5 "2024-12-18T15:26:31Z")

</div>

> [@Transistor](#):
>
> shows that each `instances` member has a `text` property but no `selected` property.

That does not explain why the script sees ".selected" for all instances except the last one. I don't believe it is required to create parameters in the instances when the object in the flex repeater already has them. The "text" parameters shown in the instances are there because they are being set by binding to a script that pulls the values from a database.

---

<div class="post-metadata">

**Author:** ![pdixon](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pdixon/32/6899_2.png) [@pdixon](https://forum.inductiveautomation.com/u/pdixon)\
**Post date:** [December 18, 2024, 3:28pm UTC](https://forum.inductiveautomation.com/t/instances-of-checkboxes-failing-on-selected-property/99969/6 "2024-12-18T15:28:42Z")

</div>

> [@Transistor](#):
>
> we can't see if you've set the PARAMS as Input/Output type

Here is the image showing the parameter types:

![Screenshot 2024-12-18 at 9.27.28 AM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/d/bdd95bedf2925e1018d01e24c5ef564bab42f55d.jpeg)

---

<div class="post-metadata">

**Author:** ![Ryan\_Deardorff](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan_deardorff/32/63815_2.png) [@Ryan\_Deardorff](https://forum.inductiveautomation.com/u/Ryan_Deardorff)\
**Post date:** [December 18, 2024, 3:49pm UTC](https://forum.inductiveautomation.com/t/instances-of-checkboxes-failing-on-selected-property/99969/7 "2024-12-18T15:49:29Z")

</div>

Make sure the "Persistent" option of the parameter is checked.

---

<div class="post-metadata">

**Author:** ![pdixon](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pdixon/32/6899_2.png) [@pdixon](https://forum.inductiveautomation.com/u/pdixon)\
**Post date:** [December 18, 2024, 3:50pm UTC](https://forum.inductiveautomation.com/t/instances-of-checkboxes-failing-on-selected-property/99969/8 "2024-12-18T15:50:31Z")

</div>

I was wrong; adding "selected" in the binding script to make it show up as a parameter in instances fixed it.

 ![Screenshot 2024-12-18 at 9.50.14 AM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/9/792a26b9fd1169f66592972df03867060e7960f1.jpeg)

---

<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:** [December 18, 2024, 3:52pm UTC](https://forum.inductiveautomation.com/t/instances-of-checkboxes-failing-on-selected-property/99969/9 "2024-12-18T15:52:39Z")

</div>

Good work. I couldn't think how `instances.0.selected` could be read if it wasn't in each of the list objects.
