Check what screen a client is open on

I use something that you could possibly use for this purpose:

  • a Global (shared) script, that implements functions WindowOpened and WindowClosed, to write who opened/closed what window to the audit_events table
  • a script on the visionWindowOpened event (and a corresponding script on the visionWindowClosed event) on every window in the project.

I use this so I can track operator actions. I’m thinking you could query the most recent WindowOpened event in the audit_events table, to see which window was most recently opened for the client of interest. I don’t know if this is the most effficient way to accomplish what I want, but it works for me.

visionWindowOpened event:

shared.WindowScript.WindowOpened(system.gui.getParentWindow(event).name, '')

Global (shared) script (named “windowScript”)

# these scripts by HAB are used to log all Operator Screen opens/closes to Audit_Events table
# called by event handler scripts on every screen - one script for ScreenOpen, one script for ScreenClosed 
def WindowOpened(WindowName, TagPath):
	Actor = system.tag.read("[System]Client/User/Username").value
	ActorHost = system.tag.read("[System]Client/Network/Hostname").value
	Action = 'OpenWindow'
	ActionTarget = WindowName
	ActionValue = TagPath
	from java.util import Date
	CurrTime = Date()
	StatusCode = 0
	OriginatingSystem = 'project='+system.tag.read("[System]Client/System/ProjectName").value
	OriginatingContext = 22  #value to enable searching for tag events
	try:
		system.db.runPrepUpdate("INSERT INTO audit_events " \
        	                    "(event_timestamp, actor, actor_host, action, action_target, " \
        	                    "action_value, status_code, originating_system, originating_context) " \
	                            "VALUES " \
	                            "(?, ?, ?, ?, ?, " \
	                            "?, ?, ?, ?)", 
 	                            [CurrTime, Actor, ActorHost, Action, ActionTarget,
	                            ActionValue, StatusCode, OriginatingSystem, OriginatingContext], 
	                            database='Ignition_SQL_App001') #must include database connection name
	except:
		pass