# How to get the View Canvas selected instance index number

**URL:** <https://forum.inductiveautomation.com/t/how-to-get-the-view-canvas-selected-instance-index-number/85011>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [January 31, 2024, 2:07pm UTC](https://forum.inductiveautomation.com/t/how-to-get-the-view-canvas-selected-instance-index-number/85011 "2024-01-31T14:07:14Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [January 31, 2024, 4:04pm UTC](https://forum.inductiveautomation.com/t/how-to-get-the-view-canvas-selected-instance-index-number/85011/2 "2024-01-31T16:04:13Z")

</div>

There are multiple ways to achieve this, depending on how you're opening the Popup and/or deleting instances.

**Opening a Popup which receives the instance index:**  
**A.** Opening the Popup from within the View that contains the chart.  
This View will automatically receive a param with a key of `index` from the Flex Repeater. You should manually place this `index` param at the View level and default it to something which would NOT make sense given the context; I recommend a value of `-1` so that when you reference the value in any scripting you can identify the default value. Now when the View opens a Popup it can pass along the index of this instance of the View.  
**B.** Opening the Popup from the Flex Repeater:  
The Flex Repeater does have an `onInstanceClick` Event, but this event is probably not the best route as you'd be forced to open your Popup via a left-click Event. Maybe this isn't so bad, because I don't see any UI in the chart View being instanced to open a Popup... I recommend placing some UI in the chart View to do so.

**Deleting a chart instance:**  
This is both simple AND complicated, because you need to determine if you're just removing an instance from your list or if you're modifying some query in order to return a different set of instances.

Wherever you want to delete an instance from the list, use `system.perspective.sendMessage("DELETE_FR_INST", params={"index": <instance_index_here>}, scope="page")`. Then configure a Message Handler listener on the Flex Repeater and allow the Flex Repeater to manage the removal logic.

Simple route:  
Inside the listener, do something like this:

```python
# deletes a specified index from the instances array/list
del self.instances[payload["index"]

```

More complicated route:  
Depending on your avenue for populating the instances list, you'll want to run the query or script again, using the listener script to specify which index to omit.

---

_[View the full topic](https://forum.inductiveautomation.com/t/how-to-get-the-view-canvas-selected-instance-index-number/85011)._
