Not able to get alert message on click of custom created button

1. I have created custom button called "SUBMIT" on module. (Working Fine)

2. I was trying to implement simple alert message on click of that button.

Process Followed:

https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_10.3/Cookbook/Adding_Buttons_to_the_Record_View/#Adding_Buttons_without_Overriding_View_Controllers

 Extend and override the record view controller:

./custom/modules/Accounts/clients/base/views/record/record.js

Code:

({

extendsFrom: 'RecordView',

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

//add listener for custom button
this.context.on('button:submit_button:click', this.submit_button, this);
},

submit_button: function() {

app.alert.show('submit-ok', {
level: 'success',
messages: 'Submitting Your Order .....',
autoClose: true
});

}
})

Please help with me with the correct  approach .

Parents
  • If you go back to the exact link you shared you will see that they are not using the record view at all, rather they are creating a new field type based on the "button".

    However, if you are wanting to modify the view controller, as you seem to be doing, you should follow the steps at the top of that page:

    https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_10.3/Cookbook/Adding_Buttons_to_the_Record_View/#Steps_To_Complete

    I am not seeing anything wrong with your code. I would check file permissions, and make sure you execute a Repair from your Admin menu. (controller changes require a Repair to take effect) Sorry, these things may seem obvious but I don't know how much you have worked with Sugar.

    Also double check your record.php to make sure the action is specified correctly, it should look something like:

    array(
        'type' => 'rowaction',
        'event' => 'button:submit_button:click',
        'name' => 'submit_button',
        'label' => 'LBL_SUBMIT_BUTTON',
        'acl_action' => 'view',
    ),

    The acl action may need to be different depending on the type of permissions you want to set for this button. But if anyone who can see the record should be able to click the button, then "view" is fine.

    Hope this gives you some ideas,

    FrancescaS

  • Followed below link:

    https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_10.3/Cookbook/Adding_Buttons_to_the_Record_View/#Steps_To_Complete

    1. Created Button .

    2.Defined label for button.

    3.Added custom button to record.php

    2 =>
    array (
    'type' => 'rowaction',
    'events' => 'button:submit_button:click',
    'name' => 'submit_button',
    'label' => 'LBL_SUBMIT_BUTTON_LABEL',
    'css_class' => 'btn btn-primary',
    'showOn' => 'edit',
    'acl_action' => 'edit',
    ),

    4..Create file called record.js at ./custom/modules/Orders/clients/base/views/record/record.js

    [record.js was not present initially so that's why I created]

    ({

    extendsFrom: 'RecordView',

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

    //add listener for custom button
    this.context.on('button:submit_button:click', this.submit_button, this);
    },

    submit_button: function() {

    app.alert.show('submit-ok', {
    level: 'success',
    messages: 'Submitting Your Order .....',
    autoClose: true
    });

    }
    })

    5. Check the permission of files (Correct) 

    6.Repair and Rebuild from Studio/Admin

    Result : No alert message on click of button

    Please check and suggest if I have missed something 

     

  • What error are you getting if any? 

    Please check your sugarcrm log, your php log, and your console log to see if you can see any errors.

  • Issue Solved : Able to get Alert Message on click on submit butto. 

    Casue Of Issue : Metadata not formatted properly.

    Thanks for the suggestions. Apprciated.

    .........................................................................................................................

    New Question : I have some APIs in Acconts/clients/base/api/mycustomAPI.php. On click of the button (which we have create above) , it should call that API. 

    Sugar CRM version used : 10.3 

    API  url :http://3.82.61.201/sugarcrm/rest/v10/Accounts/mycustomAPI/?id=62aace7c-8729-11eb-a0e4-0e1a95bf95b1

    My Code:

    ({
    extendsFrom:'RecordView',
    initialize:function(options){
    this._super('initialize',[options]);
    //add listener for custom button
    this.context.on('button:submit_button:click', this.submit_button, this);
    },
    submit_button:function(){
    app.api.call('update',app.api.buildURL('Accounts/' + this.model.get('id') + '/mycustomAPI') ,null {
    success:function(fdata)
    {
    app.alert.show('success', {
    level: 'error',
    messages: 'Activated.',
    autoClose: false
    });
    },
    error: function(error){
    app.alert.show('err', {
    level:'error',
    title: app.lang.getAppString('ERR_INTERNAL_ERR_MSG'),
    messages: err,
    autoClose: false
    });
    },
    });
    }
    })

    Please help me with the code here. !!!

  • Hello Gautam

    It looks like you are developing Sugar code - I'd suggest posting in the DevClub too so that much more developers than ones subscribed to this chapter could read your questions and share the ideas, helping you to enhance Sugar with code faster

    Good luck with overcoming coding challenges!

    Best Regards,
    Dmytro Chupylka

    integroscrm.com
    We make work in Sugar CRM system faster, more convenient and efficient

Reply Children
No Data