How to Hide button in the opportunity module menu with specific criteria (Sugar 7)?

I need lIke this js
({
    extendsFrom: 'RecordView',
    
    zipJSON: {},

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

        var salesStage = this.model.get('sales_stage'); // this is not work

         if (!(salesStage=='Verbal Conf')) {    
             $('a[name=test_form]').hide();
          }
    },  
})

Parents
  • Try this:

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

            var salesStage = this.model.get('sales_stage');

            if (salesStage != 'Verbal Conf') {
                $('a[name=test_form]').hide();
            }
        },
    })

    This way your code will execute after render instead of after initialization.

    BTW, when you said it didn't work, what did work? Try putting a 'debugger;' comment before if (salesStage != 'Verbal Conf'){     - that way you can check whether salesStage is populated. If it is populated, then the problem is with your javascript, else your problem is with populating salesStage. Which is it?

Reply
  • Try this:

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

            var salesStage = this.model.get('sales_stage');

            if (salesStage != 'Verbal Conf') {
                $('a[name=test_form]').hide();
            }
        },
    })

    This way your code will execute after render instead of after initialization.

    BTW, when you said it didn't work, what did work? Try putting a 'debugger;' comment before if (salesStage != 'Verbal Conf'){     - that way you can check whether salesStage is populated. If it is populated, then the problem is with your javascript, else your problem is with populating salesStage. Which is it?

Children
  • This is work and sales stage get correct, bit I can not find link (***** form) from the page

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

            var salesStage = this.model.get('sales_stage');
        alert(salesStage); // work good
            if (salesStage!=undefined && !(salesStage=='Verbal Conf' || salesStage=='VerbalConfSocial')) {     // work good
            alert('inner');            // work good
            if($('ul.dropdown-menu li span a[name=fusebilling_form]').length>0) alert('present'); // NOT find

             $('ul.dropdown-menu li span a[name=fusebilling_form]').parent.parent.hide(); // NOT find
            $('ul.dropdown-menu li span a[name=fusebilling_form]').hide(); // NOT find
            }
        },

    Can You Help Me?