# Perspective view Id's - to be unique or not to be?

**URL:** <https://forum.inductiveautomation.com/t/perspective-view-ids-to-be-unique-or-not-to-be/41240>\
**Category:** Ignition\
**Created:** [December 5, 2020, 10:08pm UTC](https://forum.inductiveautomation.com/t/perspective-view-ids-to-be-unique-or-not-to-be/41240 "2020-12-05T22:08:57Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![iamthebull](https://avatars.discourse-cdn.com/v4/letter/i/58f4c7/32.png) [@iamthebull](https://forum.inductiveautomation.com/u/iamthebull)\
**Post date:** [December 5, 2020, 10:08pm UTC](https://forum.inductiveautomation.com/t/perspective-view-ids-to-be-unique-or-not-to-be/41240/1 "2020-12-05T22:08:57Z")

</div>

On the [Perspective Component Methods](https://docs.inductiveautomation.com/display/DOC81/Perspective+Component+Methods) page it instructs that

> "All instances of a View will have the same ID."

 ![Screenshot from 2020-12-05 15-01-33](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/9/49fa252fe5fe10bec8cc2a817e4c9fa836df6f91.png)  
Is this the same id used in [`system.perspective.openPopup(id)`](https://docs.inductiveautomation.com/display/DOC81/system.perspective.openPopup)? Because here it suggests that this `id` will be unique(assuming we give each popup a unique id that is).

---

<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:** [December 5, 2020, 10:15pm UTC](https://forum.inductiveautomation.com/t/perspective-view-ids-to-be-unique-or-not-to-be/41240/2 "2020-12-05T22:15:02Z")

</div>

Different. You are providing it at popup time, and are responsible for uniqueness.

---

<div class="post-metadata">

**Author:** ![iamthebull](https://avatars.discourse-cdn.com/v4/letter/i/58f4c7/32.png) [@iamthebull](https://forum.inductiveautomation.com/u/iamthebull)\
**Post date:** [December 5, 2020, 10:29pm UTC](https://forum.inductiveautomation.com/t/perspective-view-ids-to-be-unique-or-not-to-be/41240/3 "2020-12-05T22:29:14Z")

</div>

I just tried the following. In an action script on a component in my popup view I ran:

`system.perspective.print(self.view.id)`

The output is:

`Input/Select From List@PSelectFromList`

and `SelectFromList` is the `id` I passed into `system.perspective.openPopup(id)`. So if I open multiple instances of my popup view and pass it a unique `id` then each instance of that view will have a unique `self.view.id`. So the blanket statement that “All instances of a View will have the same ID.” is not really correct, is it?

---

<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:** [December 5, 2020, 10:32pm UTC](https://forum.inductiveautomation.com/t/perspective-view-ids-to-be-unique-or-not-to-be/41240/4 "2020-12-05T22:32:07Z")

</div>

No, the id passed to open popup isn’t related to view.id at all. You make it up, and remember it for closePopup(). That’s it.

---

<div class="post-metadata">

**Author:** ![iamthebull](https://avatars.discourse-cdn.com/v4/letter/i/58f4c7/32.png) [@iamthebull](https://forum.inductiveautomation.com/u/iamthebull)\
**Post date:** [December 5, 2020, 10:36pm UTC](https://forum.inductiveautomation.com/t/perspective-view-ids-to-be-unique-or-not-to-be/41240/5 "2020-12-05T22:36:12Z")

</div>

Then why does it show up in the output when I print `view.id`?

---

<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:** [December 5, 2020, 10:40pm UTC](https://forum.inductiveautomation.com/t/perspective-view-ids-to-be-unique-or-not-to-be/41240/6 "2020-12-05T22:40:35Z")

</div>

Try passing in “myRandomId” and see what happens.

---

<div class="post-metadata">

**Author:** ![iamthebull](https://avatars.discourse-cdn.com/v4/letter/i/58f4c7/32.png) [@iamthebull](https://forum.inductiveautomation.com/u/iamthebull)\
**Post date:** [December 5, 2020, 10:42pm UTC](https://forum.inductiveautomation.com/t/perspective-view-ids-to-be-unique-or-not-to-be/41240/7 "2020-12-05T22:42:53Z")

</div>

Input/Select From List@PmyRandomId

---

<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:** [December 5, 2020, 10:45pm UTC](https://forum.inductiveautomation.com/t/perspective-view-ids-to-be-unique-or-not-to-be/41240/8 "2020-12-05T22:45:42Z")

</div>

I see. Very interesting. Undocumented difference for Popups.

---

<div class="post-metadata">

**Author:** ![iamthebull](https://avatars.discourse-cdn.com/v4/letter/i/58f4c7/32.png) [@iamthebull](https://forum.inductiveautomation.com/u/iamthebull)\
**Post date:** [December 5, 2020, 11:04pm UTC](https://forum.inductiveautomation.com/t/perspective-view-ids-to-be-unique-or-not-to-be/41240/9 "2020-12-05T23:04:49Z")

</div>

If a view id is not normally meant to be unique then how would you normally uniquely identify a view?

---

<div class="post-metadata">

**Author:** ![iamthebull](https://avatars.discourse-cdn.com/v4/letter/i/58f4c7/32.png) [@iamthebull](https://forum.inductiveautomation.com/u/iamthebull)\
**Post date:** [December 5, 2020, 11:13pm UTC](https://forum.inductiveautomation.com/t/perspective-view-ids-to-be-unique-or-not-to-be/41240/10 "2020-12-05T23:13:58Z")

</div>

How would you normally handle a popup closing itself? Open the popup with a unique id, pass the view it’s own id in a parameter, then the view can reference that parameter to close itself?

---

<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:** [December 5, 2020, 11:55pm UTC](https://forum.inductiveautomation.com/t/perspective-view-ids-to-be-unique-or-not-to-be/41240/11 "2020-12-05T23:55:32Z")

</div>

> [@iamthebull](#):
>
> Open the popup with a unique id, pass the view it’s own id in a parameter, then the view can reference that parameter to close itself?

This is exactly the implementation I recommend.

---

<div class="post-metadata">

**Author:** ![iamthebull](https://avatars.discourse-cdn.com/v4/letter/i/58f4c7/32.png) [@iamthebull](https://forum.inductiveautomation.com/u/iamthebull)\
**Post date:** [December 6, 2020, 12:13am UTC](https://forum.inductiveautomation.com/t/perspective-view-ids-to-be-unique-or-not-to-be/41240/12 "2020-12-06T00:13:31Z")

</div>

Do you now if there is any reason why views don’t have their own built-in unique ids for exactly this purpose?

---

<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:** [December 7, 2020, 12:37am UTC](https://forum.inductiveautomation.com/t/perspective-view-ids-to-be-unique-or-not-to-be/41240/13 "2020-12-07T00:37:53Z")

</div>

Because a View can be in use multiple places at the same time. There’s nothing to stop a session from opening multiple Popups which use the same View, FROM a “main” View which is the same View, which has Docked Views which are all the same View. Across multiple tabs. All of those Views would have the same ID if the id was built in as part of the View.

Now, even supposing you’re only talking about a View used in a Popup, I might have opened several of the same Popup but with different parameters. I only want to close the old one which is no longer in use for one reason or another and I want to keep my “new” popup open. If we closed all of the Popups with an id determined by the View, then all of my Popups would close.

---

<div class="post-metadata">

**Author:** ![iamthebull](https://avatars.discourse-cdn.com/v4/letter/i/58f4c7/32.png) [@iamthebull](https://forum.inductiveautomation.com/u/iamthebull)\
**Post date:** [December 8, 2020, 7:48pm UTC](https://forum.inductiveautomation.com/t/perspective-view-ids-to-be-unique-or-not-to-be/41240/14 "2020-12-08T19:48:37Z")

</div>

> All of those Views would have the same ID if the id was built in as part of the View.

> If we closed all of the Popups with an id determined by the View, then all of my Popups would close.

True - only if the id on the view was static (which would be pointless and impractical, as you have pointed out)

False - if the view self generated a unique id (or was provided one) each time it is instantiated.

I'm still unclear on:

> “All instances of a View will have the same ID.”

This is true, except for popup views which are assigned an id when they are opened and it's up to the opener whether or not the id assigned to the view will be unique?

---

<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:** [December 8, 2020, 9:12pm UTC](https://forum.inductiveautomation.com/t/perspective-view-ids-to-be-unique-or-not-to-be/41240/15 "2020-12-08T21:12:26Z")

</div>

> [@iamthebull](#):
>
> This is true, except for popup views which are assigned an id when they are opened and it’s up to the opener whether or not the id assigned to the view will be unique?

You seem to be assuming the Popup has some special logic for determining the id. If we generate a unique id for the popup when it is opened, how do we provide that id to the invoking component? How does that id get accessed from within the View which will be used for the Popup.

If we assume that the `id` property is a param of the View which will be used, well we're stepping on users who design their View with a param of `id` without knowing that key will be used by some piece of the application. For example: I have a FlexRepeater which pipes a row of a query to each instanced view, but my query is returning columns of `id`, `location`, and `href`. My supplied `id` param is going to contend with the `id` injected as part of the Popup Event, so we can't do that.

We _could_ generate a unique id as part of the `system.perspective.openPopup()` call (and `togglePopup` as well) and return it so that you get something like this:

```auto
popup_id = system.perspective.openPopup(*(my_args))

```

But that's useless to the View within the Popup, which is where you really want to place buttons which control the Popup. Also, this would not work for Popup ACTIONS - it would only work for scripts because actions have no way to return values.

OR

Maybe I'm misunderstanding your concerns. If your concern is that the documentation is claiming that all instances of a View will have the same ID, well, the documentation is maybe a little off, because as you mentioned I can see the identifier used to open the Popup as part of the id.  
Let me research it a bit more.

---

<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:** [December 8, 2020, 9:41pm UTC](https://forum.inductiveautomation.com/t/perspective-view-ids-to-be-unique-or-not-to-be/41240/16 "2020-12-08T21:41:22Z")

</div>

After researching this and speaking with the All-Knowing Carl, it seems like the documentation is indeed incorrect. I’ve reached out to have it fixed. The id of a View is constructed form two pieces: the path of the resource, and the mount location within the primary view.

As Popups are not “mounted” to the primary view, we directly append the id used to open the Popup to the path of the instanced View.

In instances where a view IS mounted (for example, in a component form the Embedding category), then you’ll see a path akin to this: `Popup@C$0:9[x]`. That path is the result of using a Flex Repeater to instance a View named “Popup” where “Popup” resides at Perspective/Views/Popup, and the Flex Repeater is the 9th (zero-indexed) child of the View used for the Primary View.

---

<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:** [December 8, 2020, 11:01pm UTC](https://forum.inductiveautomation.com/t/perspective-view-ids-to-be-unique-or-not-to-be/41240/17 "2020-12-08T23:01:30Z")

</div>

The documentation team has updated the doc.

---

<div class="post-metadata">

**Author:** ![iamthebull](https://avatars.discourse-cdn.com/v4/letter/i/58f4c7/32.png) [@iamthebull](https://forum.inductiveautomation.com/u/iamthebull)\
**Post date:** [December 8, 2020, 11:51pm UTC](https://forum.inductiveautomation.com/t/perspective-view-ids-to-be-unique-or-not-to-be/41240/18 "2020-12-08T23:51:22Z")

</div>

Thanks for the clarification. It really didn’t make sense for all views of the same type to have the same id. After all, what’s the point of an id if it’s not going to be unique? Each view of the same type already have the same path so it’s a bit redundant for them all to have the same id.

I was expecting similar behavior to the equivalent vision functions. When opening a popup the function returns something the calling block can use in the future to locate/identify/close the window/view. And the view/window would be able to simply close itself. The latter being possible with a popup view since the id supplied in the `openPopup` function is embedded in the view.id and can be extracted (I’m already doing that. Not sure how reliable it will be though). An auto generated id could be returned by `openPopup` for use by the calling component to close the view.
