How can i call a method (From sugar server) on the  click of custom added button?

Hi Team,

I have added a custom button on custom entity next to SAVE and CANCEL.

On the click of custom button i want to pick some value from the FORM and want to send it to one of the custom exposed method. this call should go through the sugar server so that we do not face CORS issue.

Similar thing I have done on the click of SAVE button and our business logic is inside  logic hooks.

Now i want to call the same custom method from the custom button how can i achieve it.

What is right way to achieve it.

Thanks in advance.

Regards,

Deepak

Parents Reply Children
  • Hi Deepak

    Above mention two articles by you are of two different approach but the result will be same and upgrade safe.

    We can write in both way.

    Regards

    Sam Roy

  • Hi Ramana,

    I am doing following changes please check n let me knoow if i am doing any thing wrong. after these changes i repair and rebuild and not able to open any module it shows loading all the time.

    custom/modules/module_name/clients/base/views/record/record.php

    please see changes in bold.

    <?php
    $module_name = 'PB_PBServiceConfiguration';
    $viewdefs[$module_name] =
    array (
    'base' =>
    array (
    'view' =>
    array (
    'record' =>
    array (
    'buttons' =>
    array (
    0 =>
    array (
    'type' => 'button',
    'name' => 'cancel_button',
    'label' => 'LBL_CANCEL_BUTTON_LABEL',
    'css_class' => 'btn-invisible btn-link',
    'showOn' => 'edit',
    'events' =>
    array (
    'click' => 'button:cancel_button:click',
    ),
    ),
    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:find_duplicates_button:click',
    'name' => 'find_duplicates_button',
    'label' => 'LBL_DUP_MERGE',
    'acl_action' => 'edit',
    ),
    6 =>
    array (
    'type' => 'rowaction',
    'event' => 'button:duplicate_button:click',
    'name' => 'duplicate_button',
    'label' => 'LBL_DUPLICATE_BUTTON_LABEL',
    'acl_module' => 'PB_PBServiceConfiguration',
    'acl_action' => 'create',
    ),
    7 =>
    array (
    'type' => 'rowaction',
    'event' => 'button:audit_button:click',
    'name' => 'audit_button',
    'label' => 'LNK_VIEW_CHANGE_LOG',
    'acl_action' => 'view',
    ),
    8 =>
    array (
    'type' => 'divider',
    ),
    9 =>
    array (
    'type' => 'rowaction',
    'event' => 'button:delete_button:click',
    'name' => 'delete_button',
    'label' => 'LBL_DELETE_BUTTON_LABEL',
    'acl_action' => 'delete',
    ),
    ),
    ),
    3 =>
    array (
    'customCode' => '<input id="TestButton" title="Test Button" class="button" type="button" name="TestButton" value="Test Connection">',
    ),
    4 =>
    array (
    'name' => 'sidebar_toggle',
    'type' => 'sidebartoggle',
    ),
    ),
    'panels' =>
    array (
    0 =>
    array (
    'name' => 'panel_header',
    'label' => 'LBL_RECORD_HEADER',
    'header' => true,
    'fields' =>
    array (
    0 =>
    array (
    'name' => 'picture',
    'type' => 'avatar',
    'width' => 42,
    'height' => 42,
    'dismiss_label' => true,
    'readonly' => true,
    ),
    1 => 'name',
    2 =>
    array (
    'name' => 'favorite',
    'label' => 'LBL_FAVORITE',
    'type' => 'favorite',
    'readonly' => true,
    'dismiss_label' => true,
    ),
    3 =>
    array (
    'name' => 'follow',
    'label' => 'LBL_FOLLOW',
    'type' => 'follow',
    'readonly' => true,
    'dismiss_label' => true,
    ),
    ),
    ),
    1 =>
    array (
    'newTab' => true,
    'panelDefault' => 'expanded',
    'name' => 'LBL_RECORDVIEW_PANEL1',
    'label' => 'LBL_RECORDVIEW_PANEL1',
    'columns' => 2,
    'labelsOnTop' => 1,
    'placeholders' => 1,
    'fields' =>
    array (
    0 =>
    array (
    'name' => 'servername_c',
    'label' => 'LBL_SERVERNAME',
    ),
    1 =>
    array (
    ),
    2 =>
    array (
    'name' => 'port_c',
    'label' => 'LBL_PORT',
    ),
    3 =>
    array (
    ),
    4 =>
    array (
    'name' => 'accountid_c',
    'label' => 'LBL_ACCOUNTID',
    ),
    5 =>
    array (
    ),
    6 =>
    array (
    'name' => 'password_c',
    'label' => 'LBL_PASSWORD',
    ),
    7 =>
    array (
    ),
    ),
    ),
    2 =>
    array (
    'name' => 'panel_body',
    'label' => 'LBL_RECORD_BODY',
    'columns' => 2,
    'labelsOnTop' => true,
    'placeholders' => true,
    'newTab' => true,
    'panelDefault' => 'expanded',
    'fields' =>
    array (
    0 => 'assigned_user_name',
    1 => 'team_name',
    2 =>
    array (
    'name' => 'tag',
    'span' => 12,
    ),
    ),
    ),
    3 =>
    array (
    'name' => 'panel_hidden',
    'label' => 'LBL_SHOW_MORE',
    'hide' => true,
    'columns' => 2,
    'labelsOnTop' => true,
    'placeholders' => true,
    'newTab' => false,
    'panelDefault' => 'expanded',
    'fields' =>
    array (
    0 =>
    array (
    'name' => 'description',
    'span' => 12,
    ),
    1 =>
    array (
    'name' => 'date_modified_by',
    'readonly' => true,
    'inline' => true,
    'type' => 'fieldset',
    'label' => 'LBL_DATE_MODIFIED',
    'fields' =>
    array (
    0 =>
    array (
    'name' => 'date_modified',
    ),
    1 =>
    array (
    'type' => 'label',
    'default_value' => 'LBL_BY',
    ),
    2 =>
    array (
    'name' => 'modified_by_name',
    ),
    ),
    ),
    2 =>
    array (
    'name' => 'date_entered_by',
    'readonly' => true,
    'inline' => true,
    'type' => 'fieldset',
    'label' => 'LBL_DATE_ENTERED',
    'fields' =>
    array (
    0 =>
    array (
    'name' => 'date_entered',
    ),
    1 =>
    array (
    'type' => 'label',
    'default_value' => 'LBL_BY',
    ),
    2 =>
    array (
    'name' => 'created_by_name',
    ),
    ),
    ),
    ),
    ),
    ),
    'templateMeta' =>
    array (
    'useTabs' => true,
    ),
    ),
    ),
    ),
    );

      Changes done in custom/modules/module_name/clients/base/views/record/record.js

    ({

    extendsFrom: 'RecordView',

    initialize: function (options) {
    app.view.invokeParent(this, {type: 'view', name: 'record', method: 'initialize', args:[options]});

    //add listener for custom button
    this.model.on('click #TestButton', this.buttonCalled, this);
    },

    buttonCalled:function(){
    // Write your code here
    alert("Friend am triggered.. ");
    },


    })
          

    After repiare and rebuild i am not able to load any module.

    Regards,

    Deepak

  • Hi Deepak,

    First undo your changes and save the file and do Quick R&R.

    Then clear your cache folder and also browse cache.

    Now check whether loading issue is fixed or not.

    If it fixed then dont add any customCode there.

    Once check my previous post and do it same.

    Let me for further Help.

    Best Regards

    S Ramana Raju

  • Hi Ramana,

    I have resolved the issue of loading pages.

    I have made changes suggested by you. and able to see the button next to edit button click is not working.

    Then i have followed following link:

    http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_7.5/UI_Model/Views/Examples/Adding_Buttons_to_the_Record_View/

    Following is the working code:

    record.php

    array (
    'type' => 'rowaction',
    'event' => 'button:delete_button:click',
    'name' => 'delete_button',
    'label' => 'LBL_DELETE_BUTTON_LABEL',
    'acl_action' => 'delete',
    ),

    record.js

    ({

    extendsFrom: 'RecordView',

    initialize: function (options) {
    app.view.invokeParent(this, {type: 'view', name: 'record', method: 'initialize', args:[options]});

    //add listener for custom button
    //this.model.on('button:test_connection_button:click', this.test_connection_button, this);
    this.context.on('button:test_connection_button:click', this.test_connection_button, this);
    alert("I Am initialize");
    },

    test_connection_button: function(){
    // Write your code here
    alert("Friend am triggered.. ");
    },


    })

    In the above code i am getting both alert and it is working fine. In the above approach i am added custom button/action  in action row which i do not want.

    I have two problems which i am trying to solve:

    1- I want to add custom button which should be visible while user create record and edit record. with the help of the changes which you shared, i have added the button and    that button is only visible in  EDIT record. it is not visible with create record.

    2- During the loading of edit record i got one alert which came from initialize function. which means initialize function is getting called. but while click on custom button did not get any alert.

    so could you please suggest me how can i solve both problem.   

    Thanks in advance.

    Regards,

    Deepak

  • Hi Deepak

    If you don't mind can you create new Question and post your query there.

    Here little bit clumsy.

    Best Regards

    S Ramana Raju