Odds are if you’re customising SugarCRM, you will at some point need to add functionality to the records page. This article shows you a framework for creating actions on the UI, the API entrypoints to run your code and how to link it all together using SugarCRM’s sidecar functionality.
1. Add the button In custom/modules//clients/base/views/record/record.php, you’ll need this to add the core button array.
$viewdefs[$module_name]['base']['view']['record']['buttons'] = array ( 0 => array ( 'type' => 'button', 'name' => 'cancel_button', 'label' => 'LBL_CANCEL_BUTTON_LABEL', 'css_class' => 'btn-invisible btn-link', 'showOn' => 'edit', ), 1 => array ( 'type' => 'rowaction', 'event' => 'button:save_button:click', 'name' => 'save_button', 'label' => 'LBL_SAVE_BUTTON_LABEL', 'css_class' => 'btn btn-primary', 'showOn' => 'edit', 'acl_action' => 'edit', ), 2 => array ( 'type' => 'actiondropdown', 'name' => 'main_dropdown', 'primary' => true, 'showOn' => 'view', 'buttons' => array ( 0 => array ( 'type' => 'rowaction', 'event' => 'button:edit_button:click', 'name' => 'edit_button', 'label' => 'LBL_EDIT_BUTTON_LABEL', 'acl_action' => 'edit', ), 1 => array ( 'type' => 'shareaction', 'name' => 'share', 'label' => 'LBL_RECORD_SHARE_BUTTON', 'acl_action' => 'view', ), 2 => array ( 'type' => 'pdfaction', 'name' => 'download-pdf', 'label' => 'LBL_PDF_VIEW', 'action' => 'download', 'acl_action' => 'view', ), 3 => array ( 'type' => 'pdfaction', 'name' => 'email-pdf', 'label' => 'LBL_PDF_EMAIL', 'action' => 'email', 'acl_action' => 'view', ), 4 => array ( 'type' => 'divider', ), 5 => array ( 'type' => 'rowaction', 'event' => 'button:do_some_task:click', 'name' => 'do_some_task', 'label' => 'LBL_DO_SOME_ACTION', 'acl_action' => 'view', ), 6 => array ( 'type' => 'rowaction', 'event' => 'button:find_duplicates_button:click', 'name' => 'find_duplicates_button', 'label' => 'LBL_DUP_MERGE', 'acl_action' => 'edit', ), 7 => array ( 'type' => 'rowaction', 'event' => 'button:duplicate_button:click', 'name' => 'duplicate_button', 'label' => 'LBL_DUPLICATE_BUTTON_LABEL', 'acl_module' => '', 'acl_action' => 'create', ), 8 => array ( 'type' => 'rowaction', 'event' => 'button:audit_button:click', 'name' => 'audit_button', 'label' => 'LNK_VIEW_CHANGE_LOG', 'acl_action' => 'view', ), 9 => array ( 'type' => 'divider', ), 10 => array ( 'type' => 'rowaction', 'event' => 'button:delete_button:click', 'name' => 'delete_button', 'label' => 'LBL_DELETE_BUTTON_LABEL', 'acl_action' => 'delete', ), ), ), 3 => array ( 'name' => 'sidebar_toggle', 'type' => 'sidebartoggle', ), ); Note what I’ve stored at array key 5. This is the custom button that will be rendered and the event button do_some_task will be called in the javacript file we’ll created. You can add this anywhere in the drop-down I just generally choose here.
...