Introduction to the DB elements related to scheduled reports.



The "job_queue" table is the core of all schduled events in SugarCRM. The column "target" is the name of the method that will be called when the job is run.

This job target creates new queued reports and processes due or overdue queued reports.
function::processQueue

The jobs with this target are the queued reports. The data column is the ID of the schduled report to run when the job is processed.
class::SugarJobSendScheduledReport

The table "report_schedules" stores the report schdule details. It has the ID of the report to run in the column "report_id" along with columns for the next run datetime "next_run" and the interval between runs as well as the interval in seconds "time_interval".

The table "reportschedules_users" has a column "reportschedule_id" linking it to "report_schedules" and the column "user_id" linking it to the "users" table.

SQL to gather details about what was sent to which user and when.
You will need to get the ID of the report for the queries to work.

This is a query to get a list of all users that could have gotten the report through a schedule.

SELECT uu.user_name AS "User", rs.name AS "Report Schedule", rr.name AS "Report" FROM report_schedules rs JOIN reportschedules_users ru ON ru.reportschedule_id = rs.id JOIN users uu ON uu.id = rs.user_id JOIN saved_reports rr ON rr.id = rs.report_id WHERE rs.report_id = "PUT REPORT ID HERE"; 


This query will get the full history of the scheduler runs that sent any emails for the report.

SELECT * FROM job_queue jq WHERE jq.target = "class::SugarJobSendScheduledReport" AND data IN ( SELECT id FROM report_schedules WHERE report_id = "PUT REPORT ID HERE" );