AnsweredAssumed Answered

Can't access fields in view controller

Question asked by Yury Voloshin on Jun 20, 2019
Latest reply on Jun 21, 2019 by Yury Voloshin

I'm having a problem accessing field values in a view controller. I have a controller for the Resources record view that takes a value from a dropdown and sets the value of a field depending on the dropdown selection. It looks like this:


// custom/modules/Resources/clients/base/views/record/record.js


extendsFrom: 'RecordView',


initialize: function (options) {
   this._super('initialize', [options]);
   this.model.once("sync", this.assignOnChangeFunctions, this);


assignOnChangeFunctions: function () {
   this.model.on('change:custom_rate', this.custom_rate_changed, this);


custom_rate_changed: function() {
   console.log('project_manager_l2_rate_c: ' + this.model.get('project_manager_l2_rate_c'));
   console.log('project_manager_l3_rate_c: ' + this.model.get('project_manager_l3_rate_c'));
   switch(this.model.get('custom_rate')) {
      case 'Project Manager L2':
         this.model.set('resource_rate_actual', this.model.get('project_manager_l2_rate_c'));
      case 'Project Manager L3':
          this.model.set('resource_rate_actual', this.model.get('project_manager_l3_rate_c'));



Controller for the create view looks just like the above, except it extends from CreateView and instead of this.model.once("sync", this.assignOnChangeFunctions, this) I have this.assignOnChangeFunctions. The create controller works as expected. But the record controller can't access the values of project_manager_l2_rate_c and project_manager_l3_rate_c fields. The output from console.log statements is "undefined". But, I can see the values of these fields in the database. When I try to access other fields in this Resources record, the results are mixed. Some of the fields can be accessed and others cannot. I don't see any pattern for which fields can be accessed. It seems to make no difference whether a field is in resources or resources_cstm table. Replacing this.model.once("sync", this.assignOnChangeFunctions, this) with this.assignOnChangeFunctions makes no difference. What else can I try to troubleshoot this?