HOWTO: Dynamically control the display of Edit/Detail View buttons

sugarcrmdevelopers —  February 7, 2012 — 3 Comments

Here’s a post that came up internally recently:

Is there anyway to conditionally hide the delete buttons based off something that is set in a record on a module?

And as it turns out, there is. You can access the current bean object properties right from the Smarty template itself, as well as assign other variables to the form from the view class as well. So, let’s say you wanted to have a button only show if the billing state is CA; you can use this as the customCode attribute for the button in the detailviewmeta.php file.

{if $bean->billing_address_state == "CA"}….button code….{/if}

3 responses to HOWTO: Dynamically control the display of Edit/Detail View buttons

    Cedric Mourizard February 7, 2012 at 3:35 pm

    If you want to do more complex condition you could make your test in your view, assign the result of your test to the smarty and use it on your customCode :


    This is good except it’s not upgrade safe.  Since you have to actually put the button code in there and not the {sugar_button module= type=””} code.  There is a bug filed for this and I hope it gets fixed sooner or later.


    Hi John,

    Instead of  $bean->billing_address_state == “CA” in customCode for button in detailviewdefs.php,  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

    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

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