Request Help Printing a report

I have a report that I have designed. every 5min I have a timer that checks to see if it is time to print the report.

Can I, from within the timer script, using a if clause, print the report?

Here is the code I have tried.

z= fpmi.tag.getTagValue('[]pc')
y= fpmi.tag.getTagValue('[]print_lock')
print y,z
if z == 1 and y==1:
	fpmi.tag.writeToTag('[]pc',0)
	fpmi.tag.writeToTag('[]print_lock',0)
	job = fpmi.print.createPrintJob(event.source.parent.getComponent('Report'))
	job.print(none,0)
	job1 = fpmi.print.createPrintJob(event.source.parent.getComponent('Report1'))
	job1.print(none,0)



else:	
	print "no"

I am sure it is probably something stupidly simple staring right at me. Or who knows maybe the idea can not be done in the way I am trying. That is why I am hoping the experts on here will let me know.

The error message I get when I run the above timer script is as follows:

Traceback (innermost last):
File “<TimerScript:update (15000) [Delay, Shared]>”, line 8, in ?
NameError: event

at org.python.core.Py.NameError(Py.java)
at org.python.core.PyFrame.getglobal(PyFrame.java)
at org.python.core.PyFrame.getname(PyFrame.java)
at org.python.pycode._pyx225.f$0(<TimerScript:update (15000) [Delay, Shared]>:8)
at org.python.pycode._pyx225.call_function(<TimerScript:update (15000) [Delay, Shared]>)
at org.python.core.PyTableCode.call(PyTableCode.java)
at org.python.core.PyCode.call(PyCode.java)
at org.python.core.Py.runCode(Py.java)
at com.inductiveautomation.factorypmi.application.script.ScriptManager.runCode(ScriptManager.java:245)
at com.inductiveautomation.factorypmi.application.script.TimerScriptTask.run(TimerScriptTask.java:63)
at java.util.TimerThread.mainLoop(Unknown Source)
at java.util.TimerThread.run(Unknown Source)

FactoryPMI v3.3.1 (build 2549)
Java: Sun Microsystems Inc. 1.6.0_04

Thanks and have a great day.

You don’t have the event object for client event scripts. They only exist on event handlers on components. You should either put a timer component on the window or try to get the window first:z= fpmi.tag.getTagValue('[]pc') y= fpmi.tag.getTagValue('[]print_lock') print y,z if z == 1 and y==1: fpmi.tag.writeToTag('[]pc',0) fpmi.tag.writeToTag('[]print_lock',0) rc = fpmi.gui.getWindow("WindowThatReportIsOn").getRootContainer() job = fpmi.print.createPrintJob(rc.getComponent('Report')) job.print(none,0) job1 = fpmi.print.createPrintJob(rc.getComponent('Report1')) job1.print(none,0) else: print "no"

Travis, thank you for the assistance on this. It worked as planned.

Now I only have one other question.

Is there a way to simulate a button click from within this same lines of code?

I have tried the doClick command it errors with the information the doClick is not a valid statement or something like that.

:prayer:

You can force a button to click by using the following:event.source.parent.getComponent("Button").doClick()