7

Sending reports by email is a really nice feature in CiviCRM. This is done by creating a specific cron job for each report.

However, this will be sent only at the intervals given. And they are "daily", "hourly" or "every time cron job is run". I would love to send some reports on a weekly basis, or even monthly basis. Suggestions on the forum is to set the cron to run only once a week, but I need to run the cron every minute.

Is there any way to send, by email, specific reports automatically on a weekly basis?

2 Answers 2

12

You can set up cron jobs besides the main one driving all the scheduled jobs on the Scheduled Jobs page. The way to do it is explained at http://wiki.civicrm.org/confluence/display/CRMDOC/Managing+Scheduled+Jobs#ManagingScheduledJobs-PHPclimethod

You might have your main job going every 10 minutes like:

*/10 * * * * php /path/to/civicrm/bin/cli.php -s site -u user -p password -e Job -a execute

You'll just need to add a new one for the report, let's say to send the report instance with the ID of 123 every Monday at 8:00:

0 8 * * 1 php /path/to/civicrm/bin/cli.php -s site -u user -p password -e Job -a mail_report --instanceId=123

You don't need anything in the main Scheduled Jobs page for this--this is 100% separate.

Back in the old days, this is how you had to do all scheduled jobs! Uphill--both ways!

2
  • can you extend your answer to include a second parameter - for mail_report, that would be 'format' ? Is that ...-e Job -a mail_report --instanceId=123&format=csv ?
    – commonpike
    Commented Jun 14, 2015 at 12:25
  • I don't have time to test it right now, but I'm pretty sure you want to do ... --instanceId=123 --format=csv
    – Andie Hunt
    Commented Jun 15, 2015 at 14:43
4

As noted there are various ways documented for scheduling jobs. At our organisation we wanted an easy way to allow our users to set up scheduled email reports and came up with a shared Google Sheet which lets people enter a report instance Id and reporting frequency.

The Sheet uses Google Apps Script to trigger the report generation via the URL method. The template and code has been written up here https://mashe.hawksey.info/2015/06/custom-regular-reporting-from-civicrm-with-google-sheets-and-google-apps-script/ (Disclosure: I'm the author)

[We also extended the solution to extract csv attachments and import into separate Google Sheets]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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