Adding custom create button to list-headerpane

Hi all,

I'm working on an instance of SugarServe 10.2.

Following guidance from here and this article (https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_10.2/Cookbook/Adding_Buttons_to_the_Record_View/#Defining_the_Button_Label) I've been trying to create a custom button on the Accounts module list-headerpane, however after uploading and installing my custom module, and running a Quick Repair and Rebuild, my custom button is still not appearing. Can anyone see what the issue is here?

Here is the manifest file:

<?php

$manifest = array(
'key' => 1,
'name' => 'Accounts Types',
'description' => 'Example Description',
'author' => 'CompanyNet',
'version' => '10.2.0',
'is_uninstallable' => true,
'published_date' => '2020-10-14 15:24:00',
'type' => 'module',
'acceptable_sugar_versions' =>
array(
'exact_matches' => array(
'10.2.0'
),
//or
'regex_matches' => array(
'10.*' //any 10.0 release
),
),
'acceptable_sugar_flavors' =>
array(
'PRO',
'ENT',
'ULT'
),
'readme' => '',
'icon' => '',
'remove_tables' => '',
);

I've added the custom button like so:

custom\modules\Accounts\clients\base\views\list-headerpane\list-headerpane.php

<?php
/*
* Your installation or use of this SugarCRM file is subject to the applicable
* terms available at
* support.sugarcrm.com/.../.
* If you do not agree to all of the applicable terms or do not have the
* authority to bind the entity as an authorized representative, then do not
* install or use this SugarCRM file.
*
* Copyright (C) SugarCRM Inc. All rights reserved.
*/

$viewdefs['base']['view']['list-headerpane'] = array(
'fields' => array(
array(
'name' => 'title',
'type' => 'label',
'default_value' => 'LBL_MODULE_NAME',
),
array(
'name' => 'collection-count',
'type' => 'collection-count',
),
),
'buttons' => array(
array(
'name' => 'create_button',
'type' => 'button',
'label' => 'LBL_CREATE_BUTTON_LABEL',
'css_class' => 'btn-primary',
'acl_action' => 'create',
'route' => array(
'action'=>'create'
)
),
array(
'name' => 'create_SL_button',
'type' => 'button',
'label' => 'LBL_CREATE_SL_BUTTON_LABEL',
'css_class' => 'btn btn-primary',
),
array(
'name' => 'sidebar_toggle',
'type' => 'sidebartoggle',
),
),
);

I've extended the controller as follows:

custom\modules\Accounts\clients\base\views\list-headerpane\list-headerpane.js

/*
* Your installation or use of this SugarCRM file is subject to the applicable
* terms available at
* support.sugarcrm.com/.../.
* If you do not agree to all of the applicable terms or do not have the
* authority to bind the entity as an authorized representative, then do not
* install or use this SugarCRM file.
*
* Copyright (C) SugarCRM Inc. All rights reserved.
*/
/**
* @class View.Views.Base.ListHeaderpaneView
* @alias SUGAR.App.view.views.BaseListHeaderpaneView
* @extends View.Views.Base.HeaderpaneView
*/
({
extendsFrom: 'HeaderpaneView',

/**
* @inheritdoc
*/
initialize: function(options) {
// FIXME: SC-3594 will address having child views extending metadata
// from its parent.
options.meta = _.extend(
{},
app.metadata.getView(null, 'list-headerpane'),
app.metadata.getView(options.module, 'list-headerpane'),
options.meta
);

this._super('initialize', [options]);

//shortcut keys
app.shortcuts.register({
id: 'List:Headerpane:Create',
keys: 'a',
component: this,
description: 'LBL_SHORTCUT_CREATE_RECORD',
handler: function() {
var $createButton = this.$('a[name=create_button]');
if ($createButton.is(':visible') && !$createButton.hasClass('disabled')) {
$createButton.get(0).click();
}
}
});

// Listener for custom button
this.context.on('button:create_SL_button:click', this.create_SL_button, this);
},

create_SL_button: function(evt) {
var accountType = this.model.get(this.def.cn_accounttype_c);

/**
* code goes here
*/

}
})

And I've defined the Button Label as follows:

custom\modules\Accounts\Ext\Language\en_UK.AccountsTypes.php

<?php
$mod_strings['LBL_CREATE_SL_BUTTON_LABEL'] = 'Create Social Landlord';
Parents
  • Hi,

    I have click glance of code. Seems you have missed out adding Accounts module name for viewdefs and the button css should be btn-primary.

    I have tried the below code in my local system, it is working for me, so please try replace your list-headerpane.php file with below code

    $viewdefs['Accounts']['base']['view']['list-headerpane'] = array(
    'fields' => array(
    array(
    'name' => 'title',
    'type' => 'label',
    'default_value' => 'LBL_MODULE_NAME',
    ),
    array(
    'name' => 'collection-count',
    'type' => 'collection-count',
    ),
    ),
    'buttons' => array(
    array(
    'name' => 'create_button',
    'type' => 'button',
    'label' => 'LBL_CREATE_BUTTON_LABEL',
    'css_class' => 'btn-primary',
    'acl_action' => 'create',
    'route' => array(
    'action'=>'create'
    )
    ),
    array(
    'name' => 'create_SL_button',
    'type' => 'button',
    'label' => 'LBL_CREATE_SL_BUTTON_LABEL',
    'css_class' => 'btn-primary',
    ),
    array(
    'name' => 'sidebar_toggle',
    'type' => 'sidebartoggle',
    ),
    ),
    );

    let me know if it helps you.

  • Thank you for taking a look at this

    I've made these changes but the new button is still not appearing.

    Is there something I'm doing wrong here? I've placed these files with their specified filepaths into a zip file, uploaded them into the module loader and installed them, and ran a quick repair and rebuild.

    We are using a cloud only instance. 

Reply Children
  • Can you please export your customizations from the Admin->Diagnostic Tool and have a look whether the new files have created in the path specified the manifest or not.

    Hope you have the below installdefs array in your manifest file. If you have any queries related to packaging please go through this link.

    $installdefs =array(
    'id' => 'package_123',
    'copy' => array(
    1=> array(
    'from' => '<basepath>/files/list-headerpane.php',
    'to' => 'custom\modules\Accounts\clients\base\views\list-headerpane\list-headerpane.php',
    ),
    2 => array(
    'from' => '<basepath>/files/list-headerpane.js',
    'to' => 'custom\modules\Accounts\clients\base\views\list-headerpane\list-headerpane.js',
    ),
    3 => array(
    'from' => '<basepath>/files/en_UK.AccountsTypes.php',
    'to' => 'custom\modules\Accounts\Ext\Language\en_UK.AccountsTypes.php',
    ),

    ),
    );