Print button in subpanel

Hi,
what I would like to do is create a button in the subpanel menu that prints the data inside it.
I created the button, but I don’t know how to print the data, even passing through a PDF if you want.
Anyone have an idea? Thanks

@fab
Make new window with data which you want to print and call js function window.print() .

This is what I am missing, how do I create a PDF page with subpanel data?

How is this different from selecting the records, opening the Action menu in the subpanel, and selecting Print to PDF?

I’m sorry I didn’t understand the question.
In the Action menu of the subpanel I don’t have “Print to PDF”, creating such a thing would be fine for me

Which SuiteCRM version is this?

And exactly which module, and which subpanel?

SuiteCRM Version 7.10.20
Sugar Version 6.5.25 (Version 344)

I created a custom module and a relationship to another custom module (subpanel)

Sorry, I am the one who is confused :confused:

The Print to PDF option appears in List views, but not in subpanels.

You might try to copy the code from the List view and make it work on the subpanel, but this will require a bit of technical mastery…

It might be simple to follow the suggestion above by @p.konetskiy : you don’t need a PDF to print, your browser is perfectly capable of printing HTML directly. So you can just dump some HTML into a new window a print from there.

That’s what I’m trying to do:
1- I created the button in the subpanel menu
2- for the moment the click refers to the viewdetail of the subpanel module
3- inside viewdetail there is this:

    <?php
    if(!defined('sugarEntry') || !sugarEntry) 
    	die('Not A Valid Entry Point');
    	
    require_once('include/MVC/View/views/view.detail.php');

    class <MODULE>ViewDetail extends ViewDetail {
    	function <MODULE>ViewDetail(){
    		parent::ViewDetail();
    	}
    	
    	function display(){
    		$this->populateInvoiceTemplates();
    		$this->displayPopupHtml();
    		
    		parent::display();
    	}
    	
    	function populateInvoiceTemplates(){
    		global $app_list_strings;
    		$sql = "SELECT id, name FROM aos_pdf_templates WHERE deleted = 0 AND type='<MODULE>' AND active = 1";
    		$res = $this->bean->db->query($sql);
    		$app_list_strings['template_ddown_c_list'] = array();
    		
    		while($row = $this->bean->db->fetchByAssoc($res)){
    			$app_list_strings['template_ddown_c_list'][$row['id']] = $row['name'];
    		}
    	}
    	
    	
    	function displayPopupHtml(){
    		global $app_list_strings,$app_strings, $mod_strings;
    		$templates = array_keys($app_list_strings['template_ddown_c_list']);
    		if($templates){

    		echo '	<div id="popupDiv_ara">
    				<form id="popupForm" action="index.php?entryPoint=generatePdf" method="post">
    				<table style="border: #000 solid 2px;padding-left:40px;padding-right:40px;padding-top:10px;padding-bottom:10px;font-size:110%;" >
    					<tr height="20">
    						<td colspan="2">
    						<b>'.$app_strings['LBL_SELECT_TEMPLATE'].':-</b>
    						</td>
    					</tr>';
    					
    			foreach($templates as $template){
    				if(!$template){
    					continue;

    				}
    				
    				$template = str_replace('^','',$template);
    				$js = "document.getElementById('popupDivBack_ara').style.display='none';document.getElementById('popupDiv_ara').style.display='none';var form=document.getElementById('popupForm');if(form!=null){form.templateID.value='".$template."';form.submit();}else{alert('Error!');}";
    				echo '<tr height="20">
    				<td width="17" valign="center"><a href="#" onclick="'.$js.'"><img src="themes/default/images/txt_image_inline.gif" width="16" height="16" /></a></td>
    				<td><b><a href="#" onclick="'.$js.'">'.$app_list_strings['template_ddown_c_list'][$template].'</a></b></td></tr>';
    			}
    		echo '		<input type="hidden" name="templateID" value="" />
    				<input type="hidden" name="task" value="pdf" />
    				<input type="hidden" name="module" value="'.$_REQUEST['module'].'" />
    				<input type="hidden" name="uid" value="'.$this->bean->id.'" />
    				</form>
    				<tr style="height:10px;"><tr><tr><td colspan="2"><button style=" display: block;margin-left: auto;margin-right: auto" onclick="document.getElementById(\'popupDivBack_ara\').style.display=\'none\';document.getElementById(\'popupDiv_ara\').style.display=\'none\';return false;">Cancel</button></td></tr>
    				</table>
    				</div>
    				<div id="popupDivBack_ara" onclick="this.style.display=\'none\';document.getElementById(\'popupDiv_ara\').style.display=\'none\';" style="top:0px;left:0px;position:fixed;height:100%;width:100%;background:#000000;opacity:0.5;display:none;vertical-align:middle;text-align:center;z-index:9998;">
    				</div>
    				<script>
    					function showPopup(task){
    						var form=document.getElementById(\'popupForm\');
    						var ppd=document.getElementById(\'popupDivBack_ara\');
    						var ppd2=document.getElementById(\'popupDiv_ara\');
    						if('.count($templates).' == 1){
    							form.task.value=task;
    							form.templateID.value=\''.$template.'\';
    							form.submit();
    						}else if(form!=null && ppd!=null && ppd2!=null){
    							ppd.style.display=\'block\';
    							ppd2.style.display=\'block\';
    							form.task.value=task;
    						}else{
    							alert(\'Error!\');
    						}
    					}
    				</script>';
    		}
    		else{
    			echo '<script>
    				function showPopup(task){
    				alert(\''.$mod_strings['LBL_NO_TEMPLATE'].'\');
    				}
    			</script>';
    		}
    	}
    }
    ?>

4- a new page appears with the list of PDF templates created previously and related to that module (only one). Of course this is a step that should be skipped, as the PDF should appear directly.
5- clicking on the template the error message appears:
“Error retrieving record. This record may be deleted or you may not be authorized to view it.”

@fab
I think that you took as an example the module ‘AOS_Quotes’. When you push the button with the selected template you call the file: ‘module/AOS_PDF_Templates/generatePdf.php’ . But this file is only for modules which have ‘Items’ and ‘Products’/‘Services’ . If you desided to make PDF for ‘Accounts’ you call the file ‘module/AOS_PDF_Templates/formLetter.php’ .
You should make file which will be generated in PDF specially for your module and call it.
Look at the line from code which you wrote:

...
<form id="popupForm" action="index.php?entryPoint=generatePdf" method="post">
...

ok, now I refer to formLetter.php:
in view.detail of my module I entered

require_once ('custom / modules / <MODULE> /formLetter.php');
         formLetter :: DVPopupHtml ('<MODULE>');

and now the PDF appears, but it is completely blank.
I know I should build it, but I don’t know where and how to insert the changes in formLetter.php (remembering that I have to print the records present in the subpanel)

@fab
I think that you should not entry_point but action_file.
You can make the file ‘action_file_map.php’ into ‘custom/modules/<Module_Name>/’ . (Look at an example ‘modules/Campaigns/action_file_map.php’ ) There is into the directory you can put your version of file ‘formLetter.php’ or call standard.

For analyse look at function ‘loadMapping’ in file ‘include/MVC/Controller/SugarController.php’

The line of view form should have the call similar to

...
<form id="popupForm" action="index.php?action=<name_of_action_from_file_action_file_map>?module=<Module_Name>" method="post">
...

I answer only now because I tried to deepen and follow the advice, but I do not come to the head.
I don’t think the main problem is entrypoint, the link to the pdf template appears and if I click the popup opening the PDF appears asking me how I want to open the file (which I called TEST), I choose the view in the browser but a blank page opens.
Where can I find the TEST template? If I wanted to create a PDF template file from scratch, how do I create it (so that it points directly to that file when I click)?
I saw the action_map you said, call the SubPanelViewer file, but I didn’t understand the content much

@fab

  1. I am sure that entrypoint important.
  2. You can use module ‘PDF - Templates’ for making template.
  3. The ‘modules/Campaigns/action_file_map.php’ is an example only. You can’t use the object ‘SubPanelViewer’. You shoud make your object.

I used PDF-template (called TEST) to create my template, done this, then I call it in the view.detail of my module with

require_once ('custom / modules / <MODULE> /formLetter.php');
formLetter :: DVPopupHtml ('<MODULE>');

but what appears is only a blank page.
If I get a PDF page to appear, maybe the problem is inside the PDF template, maybe I should build a new one (via code), but how?

@fab
The file ‘custom / modules / /formLetter.php’ should making pdf-file.
Pay attention to that ‘entryPoint=formLetter’ realy call the file ‘modules/AOS_PDF_Templates/formLetterPdf.php’

When I click on the template it opens the TEST.pdf, PDF file window, so I believe the file finds it and opens it.
Ah, the fact that the file formLetterPdf.php is called I’m not sure (I tried to insert some echo inside, but it doesn’t print anything), consider that currently the file formLetter.php I copied it inside my custom module and that’s where it points

@fab
I can’t comment the opening pdf file because i don’t see it.
You should use as an example file formLetterPdf.php. It is an entry point.

No, putting entrypoint formLetterPdf, the PDF does not open, but goes directly to the listview display of my module