AnsweredAssumed Answered

How to add js to record.js and prevent its  running when opening the record?

Question asked by haalvin haalvin on Jun 5, 2014
Latest reply on Apr 19, 2017 by Angel Martinez
I write some code in record.js and create-action.js to calculate field B+field C to field A. I didn't use formula because sometimes I will change the value of A not equal to the B+C.

 The code following works almost fine without one problem —— everytime I open a record, it will calculate again and rewrite the value of A,no matter what I saved before.

"record": {"controller": ({
    extendsFrom: 'RecordView',
    initialize: function (options) {
        app.view.invokeParent(this, {type: 'view', name: 'record', method: 'initialize', args:[options]});
        this.model.on("change:field_b_c",this.calculate, this);
        this.model.on("change:field_c_c",this.calculate, this);
    },
   
    calculate:function() {
       var field_b_c = this.model.get('field_b_c');
       var field_c_c = this.model.get('field_c_c');      
       var field_a_c = field_b_c+field_c_c;
       this.model.set('field_a_c',field_a_c);
    },
    _dispose: function() {
        this._super('_dispose');
    },
})


Looking for help.

Outcomes