Email Reports using Reporting Module but don't send blank reports

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

1 Like

Once upon a time I was. Now I’ve gone to the dark side (management) :rofl:

5 Likes

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.

1 Like

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?

1 Like

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

1 Like

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.