How to define a tag within a perspective button ActionPerformed Script

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:

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?

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.

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.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.

I did get it working with the following:

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?

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.

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

Also the second one would also be a popup.

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.

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.