How to hide a button on Detail View conditionally

Suppose in Specific Module i Want to Hide Delete button conditionaly from DetailView page, So where can i put condition for show/hide.

You should be able to modify this in /custom/modules/<desired_module>/metadata/detailviewdefs.php

Adding to this something like:

if (your condition) {
    unset($viewdefs['<desired_module>']['DetailView']['templateMeta']['form']['buttons'][2])
    //2 being the index of the DELETE button
}

You’ll then need to run: Admin -> Repair -> Quick Repair and Rebuild

For SugarCRM Pro version

You should edit the custom/modules/<desired_module>/metadata/detailviewdefs.php file and change the$viewdefs[$module_name][‘DetailView’][‘templateMeta’][‘form’] array according to your needs. As by default this array is empty for pretty much all modules.

Example:

// Place this code on the end of a file.
// This line remove all buttons
$viewdefs[$<desired_module>]['DetailView']['templateMeta']['form']['buttons'] = array();
// This will add some buttons according to your conditions:
if (condition for edit button = true)
    $viewdefs[$<desired_module>]['DetailView']['templateMeta']['form']['buttons'][] = 'EDIT';
if (condition for duplicate button = true)
    $viewdefs[$<desired_module>]['DetailView']['templateMeta']['form']['buttons'][] = 'DUPLICATE';
if (condition for delete button = true)
    $viewdefs[$<desired_module>]['DetailView']['templateMeta']['form']['buttons'][] = 'DELETE';

Remember to run Admin -> Repair -> Quick Repair and Rebuild every time you change this file.

Note :

Here, <desired_module> means the module name you see in the URL, for example, Contacts, Leads, etc.
Here, <any_name> means the any file name for example, custom_fields, search_fields, etc.
Here, <entry_point_name> means any name as your requirements

Hope you find this blog post helpful.

Feel free to add comments and queries, that helps us to improve the quality of posts.

You can contact us at info@infotechbuddies.com

Thank you.

Spread the love

One thought on “How to hide a button on Detail View conditionally

Leave a Reply

Your email address will not be published. Required fields are marked *