This question has been flagged
1 Reply
2799 Views

I have this JS function that is calling a controller and controller returning some values. But the problem is that var result is a promise. when I console log values i get an object with values that I need. But when I try to var product_id = result['product_template_id']; I get product_id = undefined how to I correctly get values form a promise

ProductConfiguratorFormController.include({
    _onFieldChanged: function (event) {
        event.data.changes.product_template_id = {'id': null};
        this._super.apply(this, arguments);
        var self = this;
        console.log('TESTAS')
        var result = this._rpc({
            route: '/product_configurator/contract_lines_product',
            params: {
                contract_line_id : event.data.changes.contract_line_id.id
            }
        }).then(function (values) {
          console.log(values)
        });
        var product_id = result['product_template_id'];
        var upsale = $(event.target)[0].recordData['upsale']
        var product_number = $(event.target)[0].recordData['product_id_number']
        if (!product_id) {
            return;
        }
Avatar
Discard
Best Answer

Hey, did you find how to resolve this? I can't find answer anywhere...

Avatar
Discard