# Application Module

**URL:** <https://forum.inductiveautomation.com/t/application-module/6227>\
**Category:** General Discussion\
**Created:** [April 15, 2013, 2:39am UTC](https://forum.inductiveautomation.com/t/application-module/6227 "2013-04-15T02:39:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![lcs226](https://avatars.discourse-cdn.com/v4/letter/l/848f3c/32.png) [@lcs226](https://forum.inductiveautomation.com/u/lcs226)\
**Post date:** [April 15, 2013, 2:39am UTC](https://forum.inductiveautomation.com/t/application-module/6227/1 "2013-04-15T02:39:31Z")

</div>

Hello All;

I have the following script that is executed by a client timer script. It checks a flag every 15 seconds, if true run script:

[color=#0040FF]def printReport():   
import system, app

```
print "Report print called"

```

def a():  
import system  
print “report Open called”  
system.nav.openWindow(“Report PDF”)  
print “report Opened”

```
def b():
	import system
	print "Report Printing"		
	win = system.gui.getWindow("Report PDF")
	win.getRootContainer().getComponent("Report Viewer").print(None, 0)
	print "Report should have printed"
	system.tag.writeToTag("Versa_Mill/Report_Ready_Flag", 0)
	system.nav.closeWindow("Report PDF")

system.util.invokeLater(b, 5000)

```

a()[/color]

The script only runs once after the client is first openned. You need to shutdown the client and re-open for it to work again.

Note: When the script runs it prints out the steps for the first execution. On subsequent attemps it only prints “Report print called”

Any thoughts as too why it will not execute on subsequent triggers?

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [April 15, 2013, 5:28pm UTC](https://forum.inductiveautomation.com/t/application-module/6227/2 "2013-04-15T17:28:43Z")

</div>

We don’t have enough information. What is in your timer script?

---

<div class="post-metadata">

**Author:** ![lcs226](https://avatars.discourse-cdn.com/v4/letter/l/848f3c/32.png) [@lcs226](https://forum.inductiveautomation.com/u/lcs226)\
**Post date:** [April 15, 2013, 6:23pm UTC](https://forum.inductiveautomation.com/t/application-module/6227/3 "2013-04-15T18:23:17Z")

</div>

Timer Script:

[color=#0040FF]from java.util import Date  
import app, system  
now = Date()  
ts = system.db.dateFormat(now, “H:mm:ss”) # Report generation time

printFlag = system.tag.getTagValue(“Versa\_Mill/Report\_Ready\_Flag”)

if printFlag == 1:  
app.Print\_Report.printReport()[/color]

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [April 15, 2013, 8:17pm UTC](https://forum.inductiveautomation.com/t/application-module/6227/4 "2013-04-15T20:17:21Z")

</div>

Ok, I see what is going on. Essentially, the first time the script modules are loaded the functions a() and b() get called. After that you just call the app.Print\_Report.printReport() function. You need to put the function call to a and b inside of the printReport function so it gets called every time.[code]def printReport():   
import system, app  
print “Report print called”  
app.Print\_Report.a()  
app.Print\_Report.b()

def a():  
import system  
print “report Open called”  
system.nav.openWindow(“Report PDF”)  
print “report Opened”

def b():  
import system  
print “Report Printing”   
win = system.gui.getWindow(“Report PDF”)  
win.getRootContainer().getComponent(“Report Viewer”).print(None, 0)  
print “Report should have printed”  
system.tag.writeToTag(“Versa\_Mill/Report\_Ready\_Flag”, 0)  
system.nav.closeWindow(“Report PDF”)[/code]

---

<div class="post-metadata">

**Author:** ![lcs226](https://avatars.discourse-cdn.com/v4/letter/l/848f3c/32.png) [@lcs226](https://forum.inductiveautomation.com/u/lcs226)\
**Post date:** [April 15, 2013, 8:50pm UTC](https://forum.inductiveautomation.com/t/application-module/6227/5 "2013-04-15T20:50:54Z")

</div>

Thanks Travis,

But what happened to my delay (invokelater)? Do I need to a delay for the report viewer to open before printing?

Thanks.

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [April 15, 2013, 11:40pm UTC](https://forum.inductiveautomation.com/t/application-module/6227/6 "2013-04-15T23:40:13Z")

</div>

Yes you can put that back in. Just make sure it is inside of your print function.
