HOWTO: Add buttons to detail and edit views

sugarcrmdevelopers —  January 12, 2011 — 11 Comments

I was reading this forums post yesterday, and thought it would be the perfect opportunity to discuss adding buttons to to the top of the editviews and detailviews for a module. This customization is completely metadata driven, as you can see in the code below which shows a snippet of the stock Leads detailviewdefs.

$viewdefs['Leads']['DetailView'] = array (
	'templateMeta' => array (
		'form' => array (
			'buttons' => array (
				array (
					'customCode' => '{if $bean->aclAccess("edit")}{/if}'
				array (
					'customCode' => ''

All of the buttons to be used are defined in the ‘buttons’ attribute array ( if the attribute is not there, we use the default button choices for the view ). Where the array value is a string, that maps to one of the default buttons that are defined in include/Smarty/plugins/function.sugar_button.php. You can also define the array value as an array with the lone value being ‘customCode’; this enables you to specify HTML and Smarty code for the button definition. Doing so enables you to create new custom buttons for your views.

This is also discussed in the Sugar Developer Guide.

11 responses to HOWTO: Add buttons to detail and edit views


    Thats a really very helpful. Cheers John.


    Thanks a ton.
    Just what I´ve been looking for.


    As for the $fields, what keys are in this array?  If I wanted to get the current user clicking the button, what would it be?


    Hi John,

    Instead of $bean->aclAccess(“edit”) in customCode I want to call this code:


    Where $orderProcessing is an object of my custom library class. But when I am calling this function, I am getting error  “Call to a member function isValidPendingOrderMasterStatus() on a non-object ……… in DetailView.tpl.php.

    I thought $orderProcessing  object is not assigned to smarty object. That’s why I wrote the following code in my detailviewdefs.php file.

    The code is :
    $orderProcessing = new OrderProcessing();
    $this->ss->assign(‘orderProcessing’,$orderProcessing );

    After that, Its working. But I don’t know whether my above code is valid according to Sugar standards or not.
    Please suggest if there any other way to achieve this.

    Waiting for response.
    Hrishikesh Mishra


    I have the following button to close a case as Spam in detailview:

    5=> array( ‘customCode’ => ‘ ‘, ),

    I end up with a call to:

    which yields a “Error retrieving record. This record may be deleted or you may not be authorized to view it.”


      Oops! found my problem I has “Calls” instead of “Cases”, changed to Cases and it works just fine. Thanks for the tutorial!

Trackbacks and Pingbacks:

  1. add button on detailviews - SugarCRM Forums - October 13, 2011

    […] […]

  2. Custome Button in Detail View of Module with funciton - August 29, 2012

    […] […]

  3. transfer field values from one module to another module using ajax - October 4, 2012

    […] […]

  4. Convert a Contact into Opportunity - October 8, 2012

    […] […]

  5. Adding Custom Button on the EditView - January 29, 2013

    […] […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s