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

**URL:** <https://forum.inductiveautomation.com/t/email-reports-using-reporting-module-but-dont-send-blank-reports/63562>\
**Category:** Ignition\
**Created:** [August 29, 2022, 1:20pm UTC](https://forum.inductiveautomation.com/t/email-reports-using-reporting-module-but-dont-send-blank-reports/63562 "2022-08-29T13:20:25Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![beckya](https://avatars.discourse-cdn.com/v4/letter/b/b5a626/32.png) [@beckya](https://forum.inductiveautomation.com/u/beckya)\
**Post date:** [August 29, 2022, 1:20pm UTC](https://forum.inductiveautomation.com/t/email-reports-using-reporting-module-but-dont-send-blank-reports/63562/1 "2022-08-29T13:20:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Matrix\_Engineering](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matrix_engineering/32/19781_2.png) [@Matrix\_Engineering](https://forum.inductiveautomation.com/u/Matrix_Engineering)\
**Post date:** [August 29, 2022, 1:52pm UTC](https://forum.inductiveautomation.com/t/email-reports-using-reporting-module-but-dont-send-blank-reports/63562/2 "2022-08-29T13:52:40Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [August 29, 2022, 2:10pm UTC](https://forum.inductiveautomation.com/t/email-reports-using-reporting-module-but-dont-send-blank-reports/63562/3 "2022-08-29T14:10:16Z")

</div>

> [@Matrix\_Engineering](#):
>
> @KathyApplebaum is the reporting Guru, I think

Once upon a time I was. Now I've gone to the dark side (management) 🤣

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [August 29, 2022, 2:20pm UTC](https://forum.inductiveautomation.com/t/email-reports-using-reporting-module-but-dont-send-blank-reports/63562/4 "2022-08-29T14:20:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![beckya](https://avatars.discourse-cdn.com/v4/letter/b/b5a626/32.png) [@beckya](https://forum.inductiveautomation.com/u/beckya)\
**Post date:** [August 29, 2022, 2:32pm UTC](https://forum.inductiveautomation.com/t/email-reports-using-reporting-module-but-dont-send-blank-reports/63562/5 "2022-08-29T14:32:51Z")

</div>

Thank you, could you please expound on the report data keys and what those are. An example would be extremely helpful.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [August 29, 2022, 3:11pm UTC](https://forum.inductiveautomation.com/t/email-reports-using-reporting-module-but-dont-send-blank-reports/63562/6 "2022-08-29T15:11:30Z")

</div>

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:

```python
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.

---

<div class="post-metadata">

**Author:** ![zacht](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@zacht](https://forum.inductiveautomation.com/u/zacht)\
**Post date:** [August 29, 2022, 3:52pm UTC](https://forum.inductiveautomation.com/t/email-reports-using-reporting-module-but-dont-send-blank-reports/63562/7 "2022-08-29T15:52:37Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [August 29, 2022, 3:54pm UTC](https://forum.inductiveautomation.com/t/email-reports-using-reporting-module-but-dont-send-blank-reports/63562/8 "2022-08-29T15:54:35Z")

</div>

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/Scheduling+Actions#SchedulingActions-RunScriptAction)  
[https://docs.inductiveautomation.com/display/DOC81/system.net.sendEmail](https://docs.inductiveautomation.com/display/DOC81/system.net.sendEmail)

---

<div class="post-metadata">

**Author:** ![dkeith](https://avatars.discourse-cdn.com/v4/letter/d/91b2a8/32.png) [@dkeith](https://forum.inductiveautomation.com/u/dkeith)\
**Post date:** [September 2, 2022, 7:26pm UTC](https://forum.inductiveautomation.com/t/email-reports-using-reporting-module-but-dont-send-blank-reports/63562/9 "2022-09-02T19:26:49Z")

</div>

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.
