Answers.Body: <p>As suggested by Demerit you can use alterMailParams to abort the email if the report has 0 rows. It will work on simple use case but would be difficult or need to add more logic you passing any additional parameters when running cron job or through url to filter the result since the ReportTemplate.getrows api will return the results which is saved in the database but not on fly.</p>
  
  <p>However you can using hook_civicrm_alterReportVar and set $this->_sendmail to FALSE when $rows are empty.</p>
  
  <p>HTH</p>
  
  <p>Pradeep</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-09T17:28:09.947Z
Answers.Text: Thanks @pradeep
Answers.UserDisplayName: Tapash
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-09T18:12:34.323Z
Answers.Text: Oh cool. Never knew about that.
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-09T17:04:32.570Z
Answers.LastActivityDate: 2019-05-09T17:04:32.570Z
Answers.UserDisplayName: Pradeep Nayak
Answers.Body: <p>If it were CSV you could use <a href="https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_alterMailParams/" rel="nofollow noreferrer">hook_civicrm_alterMailParams</a> and just check the attachment and if it has 0 rows then set <code>$params['abortMailSend'] = TRUE;</code> to stop it sending.</p>
  
  <p>For PDF I guess you could do the same thing, but do an api call to ReportTemplate.getrows (see api/v3/examples/ReportTemplate/Getrows.php, or the api explorer at /civicrm/api) and if it has 0 rows then abort as above.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-09T17:27:55.610Z
Answers.Text: Thanks! @Demerit
Answers.UserDisplayName: Tapash
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-09T16:40:14.033Z
Answers.LastActivityDate: 2019-05-09T16:40:14.033Z
Answers.UserDisplayName: Demerit
Answers.Body: <p>There is this extension <a href="https://civicrm.org/extensions/no-empty-report-mail" rel="nofollow noreferrer">https://civicrm.org/extensions/no-empty-report-mail</a>.</p>
  <p>Thx to<br />
  rebeccatregenna for mentioning it here: <a href="https://chat.civicrm.org/civicrm/pl/rxh86tjf7tn95jfsfttygj5aur" rel="nofollow noreferrer">https://chat.civicrm.org/civicrm/pl/rxh86tjf7tn95jfsfttygj5aur</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-08-21T18:55:46.073Z
Answers.LastActivityDate: 2024-08-21T18:55:46.073Z
Answers.UserDisplayName: petednz - fuzion
Body: <p>I need to email a report weekly to a department within organisation. Report usually sent via scheduled job in Pdf format. 
  If there's no result an email still gets sent. Is there way NOT to email an empty PDF? thanks</p>
  
Tags: <email><civireport><pdf><scheduled-job>
Title: Is there a way NOT to email if a report with no result
ThreadText: # Is there a way NOT to email if a report with no result
  
  (Asked by: username_0 on 2019-05-09)
  
  I need to email a report weekly to a department within organisation. Report usually sent via scheduled job in Pdf format.
  If there's no result an email still gets sent. Is there way NOT to email an empty PDF? thanks
  
  **Tags:** email, civireport, pdf, scheduled-job
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_1 on 2019-05-09. Score: 3
  
  As suggested by username_2 you can use alterMailParams to abort the email if the report has 0 rows. It will work on simple use case but would be difficult or need to add more logic you passing any additional parameters when running cron job or through url to filter the result since the ReportTemplate.getrows api will return the results which is saved in the database but not on fly.
  
  However you can using hook\_civicrm\_alterReportVar and set $this->\_sendmail to FALSE when $rows are empty.
  
  HTH
  
  username_1
  
  > **Comments:**
  > **username_0**: Thanks @username_1  
  > **username_2**: Oh cool. Never knew about that.  
  
  ---
  
  ### Answer by username_2 on 2019-05-09. Score: 2
  
  If it were CSV you could use [hook\_civicrm\_alterMailParams](https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_alterMailParams/) and just check the attachment and if it has 0 rows then set `$params['abortMailSend'] = TRUE;` to stop it sending.
  
  For PDF I guess you could do the same thing, but do an api call to ReportTemplate.getrows (see api/v3/examples/ReportTemplate/Getrows.php, or the api explorer at /civicrm/api) and if it has 0 rows then abort as above.
  
  > **Comments:**
  > **username_0**: Thanks! @username_2  
  
  ---
  
  ### Answer by username_3 on 2024-08-21. Score: 0
  
  There is this extension <https://civicrm.org/extensions/no-empty-report-mail>.
  
  Thx to  
  rebeccatregenna for mentioning it here: <https://chat.civicrm.org/civicrm/pl/rxh86tjf7tn95jfsfttygj5aur>
  
  
  ---
  
  