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


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.

However you can using hook_civicrm_alterReportVar and set $this->_sendmail to FALSE when $rows are empty.



  • Thanks @pradeep
    – Tapash
    May 9 '19 at 17:28
  • Oh cool. Never knew about that.
    – Demerit
    May 9 '19 at 18:12

If it were CSV you could use 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.

  • Thanks! @Demerit
    – Tapash
    May 9 '19 at 17:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.