# How to define a tag within a perspective button ActionPerformed Script

**URL:** <https://forum.inductiveautomation.com/t/how-to-define-a-tag-within-a-perspective-button-actionperformed-script/43541>\
**Category:** Ignition\
**Tags:** perspective, scripting\
**Created:** [February 17, 2021, 9:15pm UTC](https://forum.inductiveautomation.com/t/how-to-define-a-tag-within-a-perspective-button-actionperformed-script/43541 "2021-02-17T21:15:27Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![michael.black](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@michael.black](https://forum.inductiveautomation.com/u/michael.black)\
**Post date:** [February 17, 2021, 9:15pm UTC](https://forum.inductiveautomation.com/t/how-to-define-a-tag-within-a-perspective-button-actionperformed-script/43541/1 "2021-02-17T21:15:27Z")

</div>

I am trying to recreate this same script from a vision project and can’t figure out how to do it. It is an ActionPerformed Event script for when a button is pressed:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/1/21ce54d30659b91d152243b8aa0f32d562d1b4ac.png)

I dont see how I can do this within a perspective project?

Also I would like to include the folder designation before the tag “Cell/…” using view.custom.CellId and not sure how to include that in the tagpath dynamically.

Do I have to create a custom properties within the view, bind the actual tags to these custom properties and then use those within the script?

Also can I take this same code once configured correctly and put it in a project script just the same as I have it in this event script and just call this using a function name?

---

<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:** [February 17, 2021, 10:08pm UTC](https://forum.inductiveautomation.com/t/how-to-define-a-tag-within-a-perspective-button-actionperformed-script/43541/2 "2021-02-17T22:08:44Z")

</div>

> [@michael.black](#):
>
> I dont see how I can do this within a perspective project?

What part is giving you problems? Tag reading and writing is still very similar in Perspective, but depending on where you're doing this I could see some issues. `system.nav` for example is not available in Perspective, although Perspective has functions which do similar things. Are you expecting to call this from a Popup, or just a general page? As you look to have a messageBox call, I'm going to assume the button is just on a general page.

```auto
inTag = '[provider]your/tag/path'
inVal = system.tag.readBlocking([inTag])[0]
outTag = '[provider]your/other/tag/path'
outVal = system.tag.readBlocking([outTag])[0]
if inVal >= outVal:
    system.tag.writeBlocking([outTag], [outVal])
    system.perspective.closePage()
else:
    system.perspective.openPopup('identifier', 'Path/To/View', params={'msg':'Parts Out is greater than Parts In.'})

```

This of course expects that you have a View in place at "Path/To/View" which has a param key of `msg`.

This also would close the current browser tab when `closePage()` is called, which might not be what you want. I'll leave that to you.

---

<div class="post-metadata">

**Author:** ![michael.black](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@michael.black](https://forum.inductiveautomation.com/u/michael.black)\
**Post date:** [February 17, 2021, 10:45pm UTC](https://forum.inductiveautomation.com/t/how-to-define-a-tag-within-a-perspective-button-actionperformed-script/43541/3 "2021-02-17T22:45:42Z")

</div>

I did get it working with the following:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/e/4e6f1694ab6d010ec3a9b9e1baf856b6fa9aeb50.png)  
Can I put this in a script in the Scripting section, give it a function name, and call it exactly like it is by just calling that function from the button? I guess I could use the one parameter of the CellId as in input to the function? Would it still work?

---

<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:** [February 17, 2021, 10:49pm UTC](https://forum.inductiveautomation.com/t/how-to-define-a-tag-within-a-perspective-button-actionperformed-script/43541/4 "2021-02-17T22:49:36Z")

</div>

I don’t think that code should be working. `openPopup` requires two args (`id` and `view`). `closePopup` will close a Popup if the popup has an identifier of “PartsOutPopup”, but it _looks_ like that is probably the view path of the Popup you opened.

---

<div class="post-metadata">

**Author:** ![michael.black](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@michael.black](https://forum.inductiveautomation.com/u/michael.black)\
**Post date:** [February 18, 2021, 3:48pm UTC](https://forum.inductiveautomation.com/t/how-to-define-a-tag-within-a-perspective-button-actionperformed-script/43541/5 "2021-02-18T15:48:50Z")

</div>

It is a popup so would probably have to use system.perspective.closePopup().

Also the second one would also be a popup.

---

<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:** [February 18, 2021, 3:59pm UTC](https://forum.inductiveautomation.com/t/how-to-define-a-tag-within-a-perspective-button-actionperformed-script/43541/6 "2021-02-18T15:59:11Z")

</div>

My concern is not that you should not use the popup functions; my concern is that you are not using the functions correctly. Please review the [documentation](https://docs.inductiveautomation.com/display/DOC81/system.perspective.openPopup).

---

<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:** [February 18, 2021, 4:03pm UTC](https://forum.inductiveautomation.com/t/how-to-define-a-tag-within-a-perspective-button-actionperformed-script/43541/7 "2021-02-18T16:03:16Z")

</div>

> [@michael.black](#):
>
> Can I put this in a script in the Scripting section, give it a function name, and call it exactly like it is by just calling that function from the button?

Generally, yes. But if you need to use `self` or `event` in your function, you will need to pass those from the caller (the event). They won't be automatically available in your script module.
