AnsweredAssumed Answered

Generate a PDF Report in a Scheduler

Question asked by Gary Smart on Sep 8, 2016
Latest reply on Sep 8, 2016 by Ivica Nedeljkovic



Scenario: We want to send a report detailing Cases to customers each month.


Question: How can I generate a pdf report in PHP? I want to pass in values for the report's filters and get the report as a PDF so I can email it.


I've looked around the files in modules/Reports/. I seem to be able to load a report, but cannot figure out how to set parameters, run successfully or export the report.


Any guidance greatly appreciated.


Thus far I have (not much), and I'm not sure if I am on the right path - 


$bean = BeanFactory::newBean("Reports");

$sugarQuery = new SugarQuery();
$sugarQuery->from($bean, ["team_security" => false]);
$sugarQuery->where()->equals("id", "5d98b7e9-5789-e00c-3e21-57b291a02ac4");

$results = $sugarQuery->execute();

echo "Found Results: " . count($results) . "\n";

if (count($results) > 0) {
  $id = $results[0]['id'];
  $bean = BeanFactory::retrieveBean("Reports", $id, array('disable_row_level_security' => true));

  // How to set filter values???

  $bean->runReportQuery(); // Fails. Throws exception about db failure and missing fields.

  // How to get PDF?


Thanks in advance,