How to conditionally change field label name in sugar7?

How can I conditionally change a field's label name.

For example:

If I am having

this.model.get('field_name_1') as check , then the field field_name_2 should be displayed as abc or else xyz.

I expect the code changes to be made at record.js file.

Parents
  • How would you report or filter on ABC vs. XYZ?  You wouldn't be able to filter specify a filter for ABC vs. XYZ and if they were the same field and you wouldn't be able to specify one or the other in a Sugar Report.

    I think this is better and more easily accomplished by having two fields ('ABC' and 'XYZ') and using Sugar Logic to make one visible or the other depending on value of 'field_name_1'.

    App Ecosystem @ SugarCRM

Reply
  • How would you report or filter on ABC vs. XYZ?  You wouldn't be able to filter specify a filter for ABC vs. XYZ and if they were the same field and you wouldn't be able to specify one or the other in a Sugar Report.

    I think this is better and more easily accomplished by having two fields ('ABC' and 'XYZ') and using Sugar Logic to make one visible or the other depending on value of 'field_name_1'.

    App Ecosystem @ SugarCRM

Children
  • I don't need to make report of this particular field. And what if I use a non-db field here? I got the idea of two fields and conditionally hiding one. But is there any possibilities in getting the label value to change dynamically?

    Alan Beam

  • Hi Surabhil,

    I tried doing this using this.setLabel in record.js, but was having difficulty getting it to work (anyone feel free to speak up if you know how to get it working that way). But! I did get it working just by copying the contents of the setLabel function:

    // custom/modules/Accounts/clients/base/views/record/record.js
    ({
        extendsFrom:'RecordView',
        initialize:function(options){
            this.plugins=_.union(this.plugins||[],['HistoricalSummary']);
            this._super('initialize',[options]);
            this.model.on('sync', this.changeLabel, this);
        },
        changeLabel:function() {
            if(this.model.get('status_c') == 'New')
                this.$('.record-label[data-name="description"]').text('asdf');
        }
    })
    

    I hope that helps!

    -Alan