Automated reports

Hi,
I am testing both FPMI and Dream Report.
The nice thing about Dream Report is that you can say i.e. to generate a report in PDF each day and send it to person a and b and also save a copy of the report to a certain path.

Can something like this be done in FactoryPMI?
That way management doesn’t need to look for their report on a FPMI client, they just have to check their mailbox.

Any suggestions?
Thanks

Hi,

I had a play about and came up with the following - remember that this requires a FactoryPMI node to be running all the time (or at least when the report is to be generated):#Open the window containing the Report Viewer. window = fpmi.nav.openWindow("Window 1") #Get a reference to the Viewer. report = window.getRootContainer().getComponent('Report Viewer') #Close the window. fpmi.nav.closeWindow("Window 1") #Read the report as an array of bytes. data = report.getBytesPDF() #Write the report out to a file. fpmi.file.writeFile("C:\TestReport.pdf",data) #Send the report as an attachment to an email (in this case to a server requiring authentication). smtp = "smtp.server.com" sender = "factoryPMI@mycompany.com" subject = "PDF report" body = "Daily report" recipients = ["boss1@mycompany.com", "boss2@mycompany.com"] fpmi.net.sendAuthEmail(smtp, sender, subject, body, 0, recipients, "username", "password", ["TestReport.pdf"], [data]) This code should be placed in a timer script in the Global Event Scripts (under Configuration in the FactoryPMI Project Browser). The script creates a PDF file (in this case in the root of the C: drive) using a Report Viewer created in a window called Window 1 and then emails it to a couple of people. It seems to work OK but just occasionally it produces a blank PDF file. This may have to do with the timing of opening and closing the window - maybe someone from IA could comment.

If this look like working for you, you will need to add a section of code at the beginning to ensure it only runs on one machine (maybe the main server), and another section to trigger it once a day.

Let me know if you need any more help with this.

Al

Al’s code is on the right track, but what you actually have to do is open the window from the global event script, and then do an invokeLater() with a time delay for the printing/closing part, to ensure that the data from the database has come in.

I’d just like to say that this is a feature that we get asked for all the time and I’ll be the first to admit that we currently don’t have an elegant solution for, but it is in the works for V2 of the reporting plugin.

Thank you both!
Support is TOP over here.

I hope you’ll have something like Dream Report in your future version.
Then your application would have it all…

Hi Carl,

Any chance you could post a fully working version here for reference?

Al

Well, something like this seems about right:

[code]#Open the window containing the Report Viewer.
fpmi.nav.openWindow(“Window 1”)

def emailReport():
import fpmi
window=fpmi.gui.getWindow(“Window 1”)
#Get a reference to the Viewer.
report = window.getRootContainer().getComponent(‘Report Viewer’)
#Read the report as an array of bytes.
data = report.getBytesPDF()
#Send the report as an attachment to an email (in this case to a server requiring authentication).
smtp = “smtp.server.com
sender = "factoryPMI@mycompany.com"
subject = “PDF report”
body = “Daily report”
recipients = [“boss1@mycompany.com”, "boss2@mycompany.com"]
fpmi.net.sendAuthEmail(smtp, sender, subject, body, 0, recipients, “username”, “password”, [“TestReport.pdf”], [data])
#Close the window.
fpmi.nav.closeWindow(“Window 1”)

fpmi.system.invokeLater(emailReport, 5000)[/code]

but this leaves out any sort of detecting a trigger condition to actually send the report, which is usually part of a real implementation…