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

  • 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

  • Does this still work if fields are toggled between edit and detail modes?

    App Ecosystem @ SugarCRM

  • It can. I modified them so that after hitting Save, it re-evaluates what the label should say:

    // 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); // Evaluate on page load
            this.model.on('change:this.status_c', this.changeLabel, this); // Evaluate after Save (if field changes)
        },
        changeLabel:function() {
            if(this.model.get('status_c') == 'New')
                this.$('.record-label[data-name="description"]').text('New Description');
            else
                this.$('.record-label[data-name="description"]').text('Description'); // Reset if status is not "New"
        }
    })
    
  • Thanks.This works for me.
    Can we pass label constants here instead of text?

  • Yep! You can do something like this (in place of where I have "New Description"):

    app.lang.get("LBL_DESCRIPTION", "Accounts")
    
Reply Children
No Data