Converting action script to global script for window table

I had some working code in an action script initiated when an operator clicked on a button that not only opened a window, but updated a table of window names that had previously been opened to enable forward/back navigation through the queue. I’m trying to convert it to a global script (app.PageLink.PageLinkOpen), and I’ve converted the first couple of statements, but now I’m stuck on the table assignment statement. What is the syntax, or do i need to do this differently?


Original action script code:

Open the desired graphic window

fpmi.nav.openWindow(‘Backwash Primary Coalescer A’)

fpmi.nav.closeWindow(‘Page Links’)

The remainder of the code updates the list keeping track of which

windows are open for the forward/backward navigation buttons to use.

Retrieve list of open windows

windowdata = fpmi.gui.getOpenedWindows()

Use this table to store the window names into

table = event.source.parent.getComponent(“WindowList”)

Setup temporary data structure for window names

headers = [“WindowName”]
data = []
for window in windowdata:

Ignore Non-Process related windows

if (window.name != "Page Links" and window.name != "Banner"):
	data.append([window.name])

Write temporary data structure into table

table.data = fpmi.db.toDataSet(headers, data)

Update SQL database table

query = “DELETE FROM WindowQueue”
fpmi.db.runUpdateQuery(query)
order = table.getRowsInViewOrder()
row = 0
for row in order:
graphicname = table.data.getValueAt(row, 0)
graphicndx = row + 1
query = “INSERT INTO WindowQueue SET GUIname = ‘%s’, WindowQueue_ndx = ‘%d’” % (graphicname, graphicndx)
fpmi.db.runUpdateQuery(query)


Global Script Code (currently get error at table = event.source.parent.getComponent(“WindowList”). I think it needs to be something like table = event.source.data but I know I’m missing something.

def PageLinkOpen(WinName):
import fpmi

Open the desired graphic window

fpmi.nav.openWindow(WinName)

fpmi.nav.closeWindow(‘Page Links’)

#Retrieve name of SQL table by referencing client tag
winq = fpmi.tag.getTagValue("[]SQLWindowQueue")

The remainder of the code updates the list keeping track of which

windows are open for the forward/backward navigation buttons to use.

Retrieve list of open windows

windowdata = fpmi.gui.getOpenedWindows()

Use this table to store the window names into

table = event.source.parent.getComponent(“WindowList”)

Setup temporary data structure for window names

headers = [“WindowName”]
data = []
for window in windowdata:

Ignore Non-Process related windows

if (window.name != "Page Links" and window.name != "Banner"):
	data.append([window.name])

Write temporary data structure into table

table.data = fpmi.db.toDataSet(headers, data)

Update SQL database table

query = “DELETE FROM ‘%s’” % winq
fpmi.db.runUpdateQuery(query)
order = table.getRowsInViewOrder()
row = 0
for row in order:
graphicname = table.data.getValueAt(row, 0)
graphicndx = row + 1
query = “INSERT INTO ‘%s’ SET GUIname = ‘%s’, WindowQueue_ndx = ‘%d’” % (winq, graphicname, graphicndx)
fpmi.db.runUpdateQuery(query)

Well, probably the easiest thing to do to keep it the same would be to pass the event object in as an argument to the function.

However, one of the main benefits of global scripts is that you can re-use them from different windows or locations in a window- and it’s not likely that the component will be at the same relative position for each event. Therefore, you may just want to pass the actual component in as an argument.

Hope this makes sense,

Thanks, I think it did help. I still have a (hopefully) easy problem to fix. What I now have is a button with action script that passes the graphic name I want to call up, and an associated table component (named “WindowList”) that will be referenced in part of my app script:

Action Script:

graphicname = 'Purge Trip Boiler 2' tablecomp = event.source.parent.getComponent("WindowList") app.PageLink.PageLinkOpen(graphicname, tablecomp)
My app script accepts the following statements so far:

def PageLinkOpen(WinName, tableref): table = tableref
However, when the script is invoked, I get query errors because I’m not retrieving a tag value. I have a tag named SQLWindowQueue defined as text containing “p2boilerwinq”. It is not tied to PLC info, just a text string. I defined it so i could use this tag as a variable for different projects using different queues. My statement:

winq = fpmi.tag.getTagValue("[]SQLWindowQueue") 

always returns a -1 and causes the SQL queries in the script to error. What am I doing wrong with referencing the tag?

It sounds like the path to the tag is wrong… I’d double check the spelling, and also verify that it’s in the root folder, and not a deeper folder.

Regards,

The tag isn’t misspelled, but it does exist under the Client folder. However, whether I reference it as

winq = fpmi.tag.getTagValue("[]SQLWindowQueue")

or

winq = fpmi.tag.getTagValue("[]Client/SQLWindowQueue")

I get the same return of a -1 value. As another check I tried doing the same kind of tag read from a system tag:

testvar = fpmi.tag.getTagValue("[]System/Client/System/EditCount")

and that also returned a -1; the actual value displayed in the browser tree was 532.
Am I only allowed to read OPC, or DB tags into the script, but not client tags?

It appears that my suspicion is true. Once I created an OPC item in my OPC server, setup an OPC tag linked to it, and set the OPC server item value to a string value (by putting the OPC item into simulation mode) the app script read the OPC tag correctly with getTagValue. The client tags, and system tags do not appear to be accessible from an app script.

“Client” is the tag source. Try this:

winq = fpmi.tag.getTagValue("[Client]SQLWindowQueue")

So that’s what those brackets are for. Thanks for the help; that does the trick!