Add button to Detail View of Module

I did this once before and I needed to add another button so I figured I would share what I did.

the process is simple on adding a button.

I use the button to generate a form from related data. I chose to do the form pdf generation via my own means as the generate letter built into the crm did not have the functionality I required.

So we begin by editing the metadata. a blurb about it is mentioned here.
I am trying to contribute any thing I do when I get the chance as all the old sugarcrm post have been long gone. There was a whole lot of useful information on customizing sugar from back in the day.

The button add is done through the metadata

In this instance we will be editing the “Accounts” module.
Edit
custom/modules/Accounts/metadata/detailviewdefs.php

If it is not present make a copy from /modules/[‘YOUR MODULE’]/metadata/detailviewdefs.php

You will see the following


<?php
$viewdefs ['Accounts'] = 
array (
  'DetailView' => 
  array (
    'templateMeta' => 
    array (
      'form' => 
      array (
        'buttons' => 
        array (
          0 => 'EDIT',
          1 => 'DUPLICATE',
          2 => 'DELETE',
          3 => 'FIND_DUPLICATES',
          'AOS_GENLET' => 
          array (
            'customCode' => '<input type="button" class="button" onClick="showPopup();" value="{$APP.LBL_GENERATE_LETTER}">',
          ),
        ),
      ),
      'maxColumns' => '2',
      'widths' => 
      array (
        0 => 
        array (
          'label' => '10',
          'field' => '30',
        ),

we are going to add the following between ‘FIND_DUPLICATES’ and ‘AOS_GENLET’ arrays.

In this instance I am simple poping up an alert box with the ID of the current bean, yo could also simply do a window.open to an address within your server posting the bean ID to you can then pull the records and do logic and have fancy things happen.

window.open(‘ADDRESSTOYOURPHPCODE.PHP&accountID=’+’{$bean->id}’, ‘_blank’, ‘location=yes,status=yes,height=570,width=800’);


...
           3 => 'FIND_DUPLICATES',
		  4 => 
            array (
              'customCode' => '<input type="submit" class="button" title="genFile" onclick="alert(\'Bean ID: \' + \'{$bean->id}\');" name="genFile" value="genFile" />',
              'sugar_html' => 
              array (
                'type' => 'submit',
                'value' => 'genFile',
                'htmlOptions' => 
                array (
                  'class' => 'button',
                  'id' => 'genFile_button',
                  'title' => 'genFile',
                  'onclick' => 'alert(\'Bean ID: \' + \'{$bean->id}\');',
                  'name' => 'genFile',
                ),
              ),
            ),
          'AOS_GENLET' => 
          array (
...

quick repair and rebuild and you are done.

4 Likes