Not seeing session startup happen?

Working on a new perspective project. When a client starts up a new session of the application, I want to write two datetimes to custom session properties that will be used in date filter across the project.

Right now under my session Startup Script I have

def onStartup(session):
	"""
	Called when a new session is authorized and starts.

	Arguments:
		session: A reference to the newly created session
	"""
	import client.eventscripts
	import system.perspective
	system.perspective.print("About to do session startup")
	client.eventscripts.sessionStartUp(session)

and in my client.eventscripts

import system.perspective
import system.date

def sessionStartUp(session):
	system.perspective.print("Session starting!")
	now = system.date.now()
	session.custom.Filter_Plant = 0
	session.custom.Filter_StartDT = system.date.addHours(now, -8)
	session.custom.Filter_EndtDT = system.date.addHours(now, 24)
	system.perspective.print("Set times")

However, when I start a new session, the filters that are bound to session.custom.Filter_StartDT are what they were left as in designer, and I don’t see any of the print messages in my console -
image

I’ve made sure my project is saved, I’ve launched a new session from the designer, from the gateway, and directly through the URL in a incognito window, but no matter how none of my print statements show (I thought perhaps I was not creating a new session). Any thoughts on what I could be doing wrong? Using Ignition 8.1.10 here.

Currently we are testing on a corporate network so anyone who is on network can access it - no logging in required if that matters at all.

Any errors in the gateway logs? It’s possible that system.perspective.print doesn’t work right in startup scripts, since the backing session isn’t fully constructed yet; I would be somewhat surprised but could see that as a possibility.

Ah I finally did get something come through (had an issue on onPageStartup that I think was taking precedence)-

com.inductiveautomation.ignition.common.script.JythonExecException: java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: No perspective page attached to this thread.

at org.python.core.Py.JavaError(Py.java:547)

at org.python.core.Py.JavaError(Py.java:538)

at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:192)

at com.inductiveautomation.ignition.common.script.ScriptManager$ReflectedInstanceFunction.__call__(ScriptManager.java:546)

at org.python.core.PyObject.__call__(PyObject.java:461)

at org.python.core.PyObject.__call__(PyObject.java:465)

at org.python.pycode._pyx16.onStartup$1(:5)

at org.python.pycode._pyx16.call_function()

at org.python.core.PyTableCode.call(PyTableCode.java:173)

at org.python.core.PyBaseCode.call(PyBaseCode.java:306)

at org.python.core.PyFunction.function___call__(PyFunction.java:474)

at org.python.core.PyFunction.__call__(PyFunction.java:469)

at org.python.core.PyFunction.__call__(PyFunction.java:464)

at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:849)

at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:831)

at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$TrackingProjectScriptManager.runFunction(ProjectScriptLifecycle.java:689)

at com.inductiveautomation.ignition.common.script.ScriptManager$ScriptFunctionImpl.invoke(ScriptManager.java:1000)

at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$AutoRecompilingScriptFunction.invoke(ProjectScriptLifecycle.java:754)

at com.inductiveautomation.perspective.gateway.script.ScriptFunctionHelper.invoke(ScriptFunctionHelper.java:133)

at com.inductiveautomation.perspective.gateway.script.ScriptRunner.run(ScriptRunner.java:23)

at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)

at java.base/java.util.concurrent.FutureTask.run(Unknown Source)

at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at java.base/java.lang.Thread.run(Unknown Source)

Caused by: org.python.core.PyException: java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: No perspective page attached to this thread.

... 25 common frames omitted

Caused by: java.lang.IllegalArgumentException: No perspective page attached to this thread.

at com.inductiveautomation.perspective.gateway.script.AbstractScriptingFunctions.lambda$operateOnPage$0(AbstractScriptingFunctions.java:64)

at com.inductiveautomation.perspective.gateway.script.AbstractScriptingFunctions.operateOnSession(AbstractScriptingFunctions.java:120)

at com.inductiveautomation.perspective.gateway.script.AbstractScriptingFunctions.operateOnPage(AbstractScriptingFunctions.java:47)

at com.inductiveautomation.perspective.gateway.script.PerspectiveScriptingFunctions.print(PerspectiveScriptingFunctions.java:511)

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.base/java.lang.reflect.Method.invoke(Unknown Source)

at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:190)

... 22 common frames omitted

So seems like perhaps you need a page to do a system.perspective.print? Either way, I’ve removed the system.perspective.print’s as the real goal is to just set the datetimes and that still seems problematic.

The session custom properties were persistent which I removed though I don’t think that should have been necessary.

Currently the new session startup script is

import client.eventscripts
client.eventscripts.sessionStartUp(session)

and client.eventscripts

import system.perspective
import system.date

def sessionStartUp(session):
	now = system.date.now()
	# Doesn't exist
#	session.custom.Filter_Plant = 0
	session.custom.Filter_StartDT = system.date.addHours(now, -8)
	session.custom.Filter_EndtDT = system.date.addHours(now, 24)

and an example of one of the two bindings -
image

Right now when I load a new session the two datetimes picking components now come up with a red overlay and blank
image

Since my changes that caused the red overlay, I do not see any thing pop up in the logs or in the browser console. I don’t know where to go from here.

If there’s perhaps a better way to initialize these times as well, I am open to a different answer to this problem.

Can they just be custom properties with expression bindings? now(0) shouldn’t poll, so they should only evaluate once on session startup.

1 Like

I either forgot or was unaware now(0) does not poll but that that seems cleaner. It’s working! Thanks. Been a while since I’ve touched perspective.