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();
          }
    },  
})

  • 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?

  • 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?

  • Ok, so I've discovered several things. Firstly, before you click on the dropdown arrow, it's not in the DOM, and therefore can't be hidden. Secondly, for some reason, jquery isn't working (probably a conflict) so I'd recommend raw JavaScript.

    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') {
                var test_form = this.getField('test_form');
                test_form.on("render", function(){test_form.$el[0].style.display = 'none';});
                test_form.render();
            }
        },
    })

    This works for the duplicate_button field (e.g. you replace your custom test_form with this.getField('duplicate_button').

    This works by first getting the field. Then attaching a callback on rendering it that will set the display to none. Then it renders the event (so the callback fires).

    Let me know how you get on with this.