Add Generate PDF Listview Aciton Dropdown of Custom Module

We would like to add a the “Generate PDF” to the action dropdown in listview of a custom module just like it is in other modules like Leads, Contact, Accounts, etc… and keep it upgrade safe.

We have successfully added this option to the detailview of a record using the guidance from this forum.(click here for those instructions) We also need this functionality in listview. We are aware of plugins like Mail Merge Reports but it is more than what we need and printing to PDF is better suited to our needs than an actual mail merge process.

If anyone could share a detailed way to accomplish this, it would be much appreciated. I think others would find this functionality useful with their custom modules. (I’ll suggest in another topic that a future release of PDF Templates have the option to include selectable modules including custom ones).

All the information you really need to accomplish this is in that thread you linked.

Instructions on how I got this working for 7.2.1 running on LAMP (php5.5)…

This assumes you already have a “Generate PDF” button working (this will help you understand the instructions below) in your detailview of your custom module if you don’t, follow this forum posting here.

For the first step I created a YourModuleNameListviewSmarty.php file in custom/modules/YourModuleName…
I did this by copying the file LeadsListViewSmarty.php from custom/modules/leads/ then placing it in custom/modules/YourModuleName.
Then edited the file by replacing the module name “Leads” with my custom module name, for example: LeadsListViewSmarty is now “MyModuleNameListViewSmarty”, do this throughout the entire file

here is LeadsListViewSmarty.php file text below with Add to TargetList and Maps commented out…

<?php require_once('include/ListView/ListViewSmarty.php'); require_once('modules/AOS_PDF_Templates/formLetter.php'); class [b]Leads[/b]ListViewSmarty extends ListViewSmarty { function [b]Leads[/b]ListViewSmarty(){ parent::ListViewSmarty(); //$this->targetList = true; } function process($file, $data, $htmlVar) { parent::process($file, $data, $htmlVar); if(!ACLController::checkAccess($this->seed->module_dir,'export',true) || !$this->export) { $this->ss->assign('exportLink', $this->buildExportLink()); } } function buildExportLink($id = 'export_link'){ global $app_strings; global $sugar_config; $script = ""; if(ACLController::checkAccess($this->seed->module_dir,'export',true)) { if($this->export) { $script = parent::buildExportLink($id); } } // $script .= "{$app_strings['LBL_MAP']}"; return formLetter::LVSmarty().$script; } } ?>

For the 2nd step, we need to create a view.list.php file in the same place as you created the view.detail.php file which is in custom/modules/YourModuleName/views.
To do this simply copy the same file in custom/modules/leads/views to custom/modules/YourModuleName/views.

After you have the file copied over into custom/modules/YourModuleName/views you will want to edit and change the module name “leads” to YourModuleName throughout the file.

here is the view.list.php from custom/modules/leads/views…

<?php require_once('include/MVC/View/views/view.list.php'); require_once('custom/modules/[b]Leads[/b]/[b]Leads[/b]ListViewSmarty.php'); class [b]Leads[/b]ViewList extends ViewList { /** * @see ViewList::preDisplay() */ public function preDisplay(){ require_once('modules/AOS_PDF_Templates/formLetter.php'); formLetter::LVPopupHtml('Leads'); parent::preDisplay(); $this->lv = new [b]Leads[/b]ListViewSmarty(); } } After you've added these files to your custom module, refresh your listview of your custom module select at list 1 record in the list view and click on the action menu dropdown and you should see Generate Letter and as long as you have a PDF Template created for your custom module you will be able to select the template and it will download. Hope this helps out others... Cheers!

It should be noted that for certain modules, you may have to make a modification to:
modules/AOS_PDF_Templates/formletterPdf.php around lines 35-37

$module_type = $_REQUEST['module'];
$module_type_create = rtrim($module_type,'s');
$module_type_low = strtolower($module_type);

This code assumes that the singular version is different than the plural AND that the singular version simply discludes the ‘s’.

So here is what I had to do for the 2 modules I added this too:

if($module_type_create == 'Opportunitie'){
		$module_type_create = 'Opportunity';
	} else if ($module_type_create == 'preps_contracted_rep'){
		$module_type_create = 'preps_contracted_reps';

First, I added a fix for the Opportunities module, since ‘Opportunitie’ is not the singular version name,
and then I added a fix for a custom module that did not have a difference between plural and singular names.