# Flex Repeater - Get Selected Instance

**URL:** <https://forum.inductiveautomation.com/t/flex-repeater-get-selected-instance/29847>\
**Category:** Ignition\
**Created:** [November 11, 2019, 3:28pm UTC](https://forum.inductiveautomation.com/t/flex-repeater-get-selected-instance/29847 "2019-11-11T15:28:16Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![alainia.spencer](https://avatars.discourse-cdn.com/v4/letter/a/6a8cbe/32.png) [@alainia.spencer](https://forum.inductiveautomation.com/u/alainia.spencer)\
**Post date:** [November 11, 2019, 3:28pm UTC](https://forum.inductiveautomation.com/t/flex-repeater-get-selected-instance/29847/1 "2019-11-11T15:28:16Z")

</div>

Is there a way to figure out what instance of a template that is selected on a Flex repeater? For an example, If i am currently showing 10 instances of a template, I would like to know what instance a user selects. This is similar to getting data out of a template repeater by using the .getLoadedTemplates() method in Vision.

---

<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:** [November 11, 2019, 4:31pm UTC](https://forum.inductiveautomation.com/t/flex-repeater-get-selected-instance/29847/2 "2019-11-11T16:31:03Z")

</div>

Short answer: no.  
Long answer: Don't rely on the Flex Repeater to handle this for you; let your Views do the work with Message Handlers.

Setup:  
Let the View being instanced accept a param (like `index` - this param is passed along free for all instances of the Flex Repeater without you needing to supply anything yourself).  
 ![17%20AM](https://us1.discourse-cdn.com/inductiveautomation/original/2X/2/216e2b450cf5fbd02f3734b01a6b292878c9b99a.png)

on the ROOT node of the View, configure an onClick event to execute a Script Action with the following code:

```auto
system.perspective.sendMessage('ROOTCLICK', payload={'index': self.view.params.index}, scope='page')

```

Now go to the Flex Repeater, right-click the Flex Repeater, and select "Configure Scripts...".  
Under Message Handlers, add a new handler with a message type of "ROOTCLICK", and supply the following code:

```auto
self.custom.selected = payload['index']

```

Now your Flex Repeater is aware of which instance was most recently clicked.

---

<div class="post-metadata">

**Author:** ![alainia.spencer](https://avatars.discourse-cdn.com/v4/letter/a/6a8cbe/32.png) [@alainia.spencer](https://forum.inductiveautomation.com/u/alainia.spencer)\
**Post date:** [November 11, 2019, 10:30pm UTC](https://forum.inductiveautomation.com/t/flex-repeater-get-selected-instance/29847/3 "2019-11-11T22:30:47Z")

</div>

Hmmm, I am obviously doing something incorrect here.

1. I created a custom parameter on the view that has the template repeater on it called index.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/4/4ba6be974dc4052894b6d42d6071d97d26313604.png)

2. The instances on my flex repeater contains a index and a tag path:  

3. I added the following to the root container onClick Event:

system.perspective.sendMessage(‘ROOTCLICK’, payload={‘index’:self.view.params.index}, scope=‘page’)

1. I created a new message handler called ‘ROOTCLICK’ on the template repeater with the following code (I am writing the results to a text tool so that I can see):  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/b/b225410c7a1e316224387033547e48f5d1c8d8d0.png)

It does look like the Event is being called, but the value is not being passed to the View ‘index’ parameter.

Thoughts?

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/6/62a964c77eec2f3171f76720363d6e807eb864c8.png)

---

<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:** [November 11, 2019, 10:34pm UTC](https://forum.inductiveautomation.com/t/flex-repeater-get-selected-instance/29847/4 "2019-11-11T22:34:19Z")

</div>

It is not writing to that parameter, it is writing to `FlexRepeater.custom.selected`.

> [@alainia.spencer](#):
>
> I created a new message handler called ‘ROOTCLICK’ on the template repeater with the following

See how you're modifying the Flex Repeater (please don't call it the Template Repeater - that's a Vision concept) and specifying `self.custom.selected`?

---

<div class="post-metadata">

**Author:** ![alainia.spencer](https://avatars.discourse-cdn.com/v4/letter/a/6a8cbe/32.png) [@alainia.spencer](https://forum.inductiveautomation.com/u/alainia.spencer)\
**Post date:** [November 11, 2019, 10:38pm UTC](https://forum.inductiveautomation.com/t/flex-repeater-get-selected-instance/29847/5 "2019-11-11T22:38:21Z")

</div>

Ahhh I got it!!! Silly me, I put the code on the WRONG view!

It’s working, thank you!!!

---

<div class="post-metadata">

**Author:** ![YF129701](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/yf129701/32/60498_2.png) [@YF129701](https://forum.inductiveautomation.com/u/YF129701)\
**Post date:** [July 13, 2022, 8:24pm UTC](https://forum.inductiveautomation.com/t/flex-repeater-get-selected-instance/29847/6 "2022-07-13T20:24:02Z")

</div>

Are there any plans to pass certain parameters into Flex Repeater instances like the Perspective Table does? See my post here: [Documentation on what is passed to table cell rendered as view - #4 by PGriffith](https://forum.inductiveautomation.com/t/documentation-on-what-is-passed-to-table-cell-rendered-as-view/53951/4)

---

<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:** [July 14, 2022, 2:22am UTC](https://forum.inductiveautomation.com/t/flex-repeater-get-selected-instance/29847/7 "2022-07-14T02:22:22Z")

</div>

To my knowledge - aside from params you specify yourself - the only value passed along to each instance [is the index of that instance](https://docs.inductiveautomation.com/display/DOC81/Perspective+-+Flex+Repeater#:~:text=The%20object%C2%A0will%20usually%20contain%20one%20or%20more%20parameters%2C%20including%20the%20instance%27s%20own%20index%2C%20that%20will%20be%20passed%20into%20that%20particular%20instance.%20As%20a%20side%20note%2C%20overwriting%20the%20index%20parameter%20is%20not%20recommended.).

---

<div class="post-metadata">

**Author:** ![j.abrante](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/j.abrante/32/10431_2.png) [@j.abrante](https://forum.inductiveautomation.com/u/j.abrante)\
**Post date:** [July 18, 2022, 12:00pm UTC](https://forum.inductiveautomation.com/t/flex-repeater-get-selected-instance/29847/8 "2022-07-18T12:00:00Z")

</div>

How I can take the index instance?

---

<div class="post-metadata">

**Author:** ![YF129701](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/yf129701/32/60498_2.png) [@YF129701](https://forum.inductiveautomation.com/u/YF129701)\
**Post date:** [July 18, 2022, 2:18pm UTC](https://forum.inductiveautomation.com/t/flex-repeater-get-selected-instance/29847/9 "2022-07-18T14:18:22Z")

</div>

Add an `index` param on the view that you specify the path for on the Flex Repeater. Then you can use that param for whatever you need. For instance, I have a delete button on the view I’m repeating - when that button gets clicked, I send a message back to the repeater to remove the instance. Does that make sense @j.abrante?

---

<div class="post-metadata">

**Author:** ![jd1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jd1/32/18928_2.png) [@jd1](https://forum.inductiveautomation.com/u/jd1)\
**Post date:** [July 18, 2022, 4:46pm UTC](https://forum.inductiveautomation.com/t/flex-repeater-get-selected-instance/29847/10 "2022-07-18T16:46:27Z")

</div>

Would you mind sharing your code of how you are removing the instance?

---

<div class="post-metadata">

**Author:** ![YF129701](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/yf129701/32/60498_2.png) [@YF129701](https://forum.inductiveautomation.com/u/YF129701)\
**Post date:** [July 18, 2022, 5:09pm UTC](https://forum.inductiveautomation.com/t/flex-repeater-get-selected-instance/29847/11 "2022-07-18T17:09:49Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/8/b802a11e662ca0a01b34213456a7a986a1498486.png)  
This is a simple component. When I press ‘x’ icon, it executes this `onClick` event:

```python
msg = "del_instance_by_id"
system.perspective.sendMessage(msg, payload = {"index": self.view.params.index})

```

Then, on the Flex Repeater, I created a script (right-click, Configure Scripts…) and named it `del_instance_by_id` or whatever you want to call your message.

```python
idx = payload["index"] # receive payload from message
try:
    del self.props.instances[idx]
except:
    # handle exception (log, print, etc)

```

This works for me - there are probably many ways to do it, though.

---

<div class="post-metadata">

**Author:** ![jd1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jd1/32/18928_2.png) [@jd1](https://forum.inductiveautomation.com/u/jd1)\
**Post date:** [July 18, 2022, 5:12pm UTC](https://forum.inductiveautomation.com/t/flex-repeater-get-selected-instance/29847/12 "2022-07-18T17:12:40Z")

</div>

Thank you!

---

<div class="post-metadata">

**Author:** ![drewdin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drewdin/32/3363_2.png) [@drewdin](https://forum.inductiveautomation.com/u/drewdin)\
**Post date:** [June 26, 2025, 1:44am UTC](https://forum.inductiveautomation.com/t/flex-repeater-get-selected-instance/29847/13 "2025-06-26T01:44:57Z")

</div>

Is this still the preferred method?
