Hi Andy,
This is not an elegant solution (nor upgrade safe) but essentially here’s what I did to accomplish what rossi was asking about above:
-
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);} 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.