Error Executing Tag Change Script

Hello im using Ignition 7.9 and ive encountered an error i dont really understand using a gateway tag change script. When i use memory tags for the tests, it works perfectly but with opc tags the script doesnt execute properly and shows that error. Can anyone give me a hand over this? thanks in advance.

this is the error

com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last): File "", line 36, in java.lang.NullPointerException java.lang.NullPointerException: java.lang.NullPointerException

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

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

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

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

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

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

at org.python.pycode._pyx138431.f$0(:50)

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

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

at org.python.core.PyCode.call(PyCode.java:18)

at org.python.core.Py.runCode(Py.java:1275)

at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:634)

at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:601)

at com.inductiveautomation.ignition.common.script.TagChangeScriptExecutor$TagChangeExecutionCallback.execute(TagChangeScriptExecutor.java:192)

at com.inductiveautomation.ignition.common.script.TagChangeScriptExecutor$TagChangeExecutionCallback.execute(TagChangeScriptExecutor.java:135)

at com.inductiveautomation.ignition.common.util.SerialExecutionQueue$PollAndExecute.run(SerialExecutionQueue.java:96)

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

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

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

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

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

Caused by: org.python.core.PyException: Traceback (most recent call last): File "", line 36, in java.lang.NullPointerException java.lang.NullPointerException: java.lang.NullPointerException

... 21 common frames omitted

and this is the script

if not initialChange:

	tagpath = str(event.tagPath)
	
	retort = tagpath[30:31]
	action = tagpath[32:]
	
	value = int(newValue.value)
	
	datetimestamp = system.date.now()
	database = project.constants.database()
	
	cycletag = 'JEREZ/AUTOCLAVES/AUTOCLAVE' + retort + '/CYCLE'
	cycle = system.tag.read(cycletag).value
	
	if action == 'VALVLES/WATER': #This is the action 2 LLENADO MINIMO
		minleveltag = 'JEREZ/AUTOCLAVES_ING/AUTOCLAVE' + retort + '/LEVELS/MIN_LEVEL'
		minlevel = system.tag.read(minleveltag).value
		if value and minlevel == 0:
			#We have the water valve opened and the min level not reached.
			query = '''
						INSERT INTO RETORT_ACTIVITY (RETORT, CYCLE, SUBPHASE, STARTTIME)
						VALUES (?, ?, ?, ?)
					'''
			args = [retort, cycle, 2, datetimestamp]
			system.db.runPrepUpdate(query, args, database)
		
	if action == 'LEVELS/MIN_LEVEL':
		if value:
			query = '''
						SELECT MAX(STARTTIME) FROM RETORT_ACTIVITY
						WHERE RETORT = ? AND SUBPHASE = 2 AND ENDTIME IS NULL
					'''
			args = [retort]
			starttime = system.db.runScalarPrepQuery(query, args, database)
			elapsedtime = system.date.secondsBetween(starttime, datetimestamp)
			
			query = '''
						UPDATE RETORT_ACTIVITY SET ENDTIME = ?, ELAPSED = ?
						WHERE RETORT = ? AND SUBPHASE = 2 AND ENDTIME IS NULL
					'''
			args = [datetimestamp, elapsedtime, retort]
			system.db.runPrepUpdate(query, args, database)

Please edit your post to use this forum’s pre-formatted text markers instead of attempting to use html “blockquote”. (Three reverse-quotes on separate lines above and below the pasted code or backtraces. Or use the </> button while the pasted text is highlighted.)

Also, what line is line 36 in your script? Pretend I can’t count to 36

Nullpointer means it isnt getting a value… probably whatever is at line 36.
But the code you provided doesnt start from line 1 does it?

i found the problem, i was getting null value from databate and added a filter to set it to zero if i had no valuem sry for the late reply