Hi Samuka,
Yes I was able to do this. Itās not an elegant solution (nor upgrade safe) but essentially hereās what I did:.
-
Make sure you have the āGenerate Letterā option working on your custom module, ādetail viewā page: see this thread for that information: https://suitecrm.com/forum/developer-help/1379-no-preview-option-in-pdf-templates?limitstart=0
-
Hereās where I believe there may be a better way of doing this, but I was able to get it working:
formLetterPdf.php is the file that gets executed when a template is selected from the āGenerate Letterā button above.
Edit formLetterPdf.php in /modules/AOS_PDF_Templates to include an āifā statement specific to only include your custom module type (after the "if(isset($_REQUEST)ā¦ else{ $recordIds = explode(ā,ā,$_REQUEST[āuidā]);} statement:
if ($module_type === āyour_custom_moduleā)
Copy everything from ā$template = new AOS_PDF_Templates();ā and down in this file and put inside of this new if statement (just copy and leave the old code there for the āelseā statement).
Above what you just copied, to pull in the related records for a particular record, use this:
$example = BeanFactory::getBean(āyour_custom_moduleā, $_REQUEST[uid]);
$related_records = $example->get_linked_beans(ārelated_linkā);
Where ārelated_linkā would be the link field defined in the moduleās vardef file (see this post: https://suitecrm.com/suitecrm/blog/entry/get-linked-beans-in-suitecrm-7-4-1-onwards)
Now that you have your related records pulled into the array $related_records youāll have to build a new array that will include the fields from your related records for use in your PDF. I accomplished this with use of a āforeachā statement:
$relatedarr = array();
$rowcount = 0;
$colcount = 0;
foreach($related_records as $related_record){
$relatedarr[$rowcount][$colcount] = $related_record -> some_field_name;
$relatedarr[$rowcount][$colcount+1]= $related_record -> some_other_field_name;
.
.
.
$rowcount++;
}
This also allowed me to keep a record of how many rows ($rowcount) I would eventually need to print out in the PDF to contain the related records.
Once you have your ārelatedarrā array built you can use this to build the HTML variable ($newhtml) that needs to be inserted into the $pdf->writeHTML($newhtml) line in the copied text mentioned above to produce the PDF.
Make sure and create an empty template of type āyour_custom_moduleā to use as the template to select after the āGenerate Letterā popup appears. The HTML for the PDF is completely written in the formLettterPdf.php file so adding anything in this template will not be used when the file executes. You can, however, use the header and footer settings in this empty template as these are still passed through in your new āifā statement above.
As noted above, this is NOT upgrade safe and will only work with one template and one module type, but for my purposes it worked out really well. Someone with more experience can probably clean up/improve my process above but I thought Iād share this to help anyone get started ā
Thanks guys and look forward to hearing your feedback.