I am building a custom entry point for our SuiteCRM, and I want to retrieve the data from two different reports already created with reports module, then based on both reports data I will retrieve extra data from a 3rd API service and then I will display the whole data to the user for confirmation.
$bean = BeanFactory::GetBean('AOR_Reports');
$report = $bean->retrieve($report_id);//Load Report
The above will retrieve the proper report but not the actual results
Is there anything like:
$results=$report->run()
Thank you in advance!
I am still trying to figure out the above, I’ll post an update.
Since I haven’t find yet, a command like
$results=$report->run()
I thought I could use the "Export’ of a report that is a csv file, so I tried
$results=file_get_contents("http://<path-to-SuiteCRM>/index.php?module=AOR_Reports&record=<report-id>&action=Export");
echo $results;
But I am getting a login screen, that if I use my credentials the file gets downloaded. Probably this is something about the session and the cookies(?).
This will be triggered automated so user login is not an option.
Should I use curl instead of file_get_contents?
Any help is appreciated!
… a bit disappointed that no one post an answer or just a hint/tip.
Anyway I managed to retrieve a report’s data with the below:
$bean = BeanFactory::GetBean('AOR_Reports',$report_id);//Load Report
$query=$bean->build_report_query(); //Get query
$result = $bean->db->query($query); //Execute query
if ($result->num_rows>0){
$data = $bean->db->fetchByAssoc($result); //Fetch data
}
It doesn’t contain the report headers but it is fine for me.
Enjoy!
1 Like
Today I figure out that my previous post was returning only one first of data.
UPDATE:
$bean = BeanFactory::GetBean('AOR_Reports',$report_id);//Load Report
$query=$bean->build_report_query(); //Get query
$result = $bean->db->query($query); //Execute query
$i=0;
if ($result->num_rows>0){
while ($row = $bean->db->fetchByAssoc($result)) { //Fetch data and create table
$data[$i] = $row;
$i++;
}
}
In the end everything you need is in the $data
5 Likes