0

i am trying to call a js function from another function. But I am getting an error.

*.js

    reset: async function (record, ev) {
      // var self=this;
      if (ev && ev.target === this) {
          this.restoreProductTemplateId = this.recordData.product_template_id;
          this.optionalProducts = (ev.data && ev.data.optionalProducts) || this.optionalProducts;
      }
      console.log('this',this);
      await this._super(...arguments);
        if (ev && ev.target === this) {
            if (ev.data.changes && !ev.data.preventProductIdCheck && ev.data.changes.product_template_id) {
              console.log('inside if');
                this._onTemplateChange(record.data.product_template_id.data.id, ev.data.dataPointID);
            } else if (ev.data.changes && ev.data.changes.product_id) {
              console.log('inside else if');
                this._onProductChange(record.data.product_id.data && record.data.product_id.data.id, ev.data.dataPointID).then(wizardOpened => {
                    if (!wizardOpened) {
                      console.log('inside wizardOpened',wizardOpened);
                        console.log('this',this);
                        this._onLineConfigured();
                        // this.amhere();
                    }
                });
            }
        }
    },
    _onLineConfigured: function(){
      // alert('am here 77777777777');
      var ff = 0.0;
      console.log('ff',ff);
      var self = this;
      this._super.apply(this, arguments);

      var parentList = self.getParent();
      var unselectRow = (parentList.unselectRow || function() {}).bind(parentList); // form view on mobile
      if (self.optionalProducts && self.optionalProducts.length !== 0) {
              self.trigger_up('add_record', {
                  context: self._productsToRecords(self.optionalProducts),
                  forceEditable: 'bottom',
                  allowWarning: true,
                  onSuccess: function () {
                      // Leave edit mode of one2many flist.
                      unselectRow();
                  }
              });
          }else if (!self._isConfigurableLine() && self._isConfigurableProduct()) {
                  // Leave edit mode of current line if line was configured
                  // only through the product configurator.
                  unselectRow();
              }
    },

ow can I solve this?

KbiR
  • 4,047
  • 6
  • 37
  • 103

1 Answers1

0

This is probably caused by the fact that you are accessing an inner this in the .then body. The solution is to define an outer this an access it instead of the inner this:

   reset: async function (record, ev) {
      ...
      // This should fix it
      outer_this = this;
      ...
      this._onProductChange(record.data.product_id.data && 
      record.data.product_id.data.id, ev.data.dataPointID).then(wizardOpened => {
                    if (!wizardOpened) {
                        // Note that I am accessing the outer this
                        outer_this ._onLineConfigured();
                    }
                });
            }
        }
    },
    _onLineConfigured: function(){
      ...
    },
Josip Domazet
  • 2,246
  • 2
  • 14
  • 37