I am trying to set up an action to email a report using the reporting module, but not send blank reports. I am assuming I can use the Run script action but have no idea where to start. Any help would be appreciated.
OK, so I havenât done this so just offering âsome helpâ not all help.
Your runscript would call:
https://docs.inductiveautomation.com/display/DOC81/system.report.executeAndDistribute
As to checking the report size, I would assume there is a way to check the byte size and if less than a current value etc, donât send it.
@KathyApplebaum is the reporting Guru, I think
Once upon a time I was. Now I've gone to the dark side (management)
If youâre using a script action, you have access to the reportâs data keys directly.
Only you, as the report author, will known which data key(s) will mean an empty report, so youâd have to drive some logic off of that. Based on that condition being met, you could then use executeAndDistribute
to call some other âthe report is goodâ email action.
Thank you, could you please expound on the report data keys and what those are. An example would be extremely helpful.
The Run Script action gets a dataMap
parameter as input.
This is a dictionary of report data keys. If you have a top level datakey called, I donât know, reportData
, and want to not execute the report when thereâs no data, it would be something like this:
ds = dataMap["reportData"]
if ds.rowCount > 0:
system.report.executeAndDistribute( # fill in actual parameters )
Thereâs really not a lot to it - you will just have to fill in the correct name for the report data key(s) that drive your logic, and either have an additional email action set up (that will be fired by this script action) or use system.report.execute
and system.net.sendEmail
. Dealerâs choice.
If you use system.report.executeAndDistribute
inside a reportâs scheduled âRun Scriptâ action, does this report run twice (SQL queries and such)? Once for the reportâs schedule and again for the system.report.executeAndDistribute
call?
Thatâs a good point. Youâd want to use the reportBytes
parameter and directly email it, then:
https://docs.inductiveautomation.com/display/DOC81/Scheduling+Actions#SchedulingActions-RunScriptAction
https://docs.inductiveautomation.com/display/DOC81/system.net.sendEmail
Our setup doesnât use the built in Report Scheduler, but a home-built script process that schedules, runs, and distributes reports. Every report has a boolean parameter called âEmptyâ. When that flag is true, the report immediately exits and returns no data (just the headers).
The execution script calls each report twice: once with the empty flag true and once false. If the byte count of the two result sets are the same, then the report returned no data. [we actually still send the email to prove report execution, but the subject line states: âreport is emptyâ]. If the two datasets are different, then a normal report email is delivered.
I donât know if a similar technique could be used inside the IA Report Scheduler. Iâd have to think about that.