0
votes

I Use odoo 10 and want to change pivot_view.js

I'm really confused with this code. I can't change the value. Can you explain me about the right code ? This is my code :

    var value = false;

    new Model('lhp.master').call('getValues', ['date', 'idx']).then(
       function (result) { value = result[0];  }
    );

    console.log('value =',value);

Thank you for your help.

1

1 Answers

1
votes

I think the problem is with how javascript promises work!

The order of the execution of the code is a s follows:

  1. var value = flase;
  2. calling the server method getValue by sending an http request;
  3. console.log('value =',value); // which will print "value =fasle" on the console
  4. after the http request earlier in step 2 is finished and a response is retrieved from the server. The callback function will be called with the result:

    function (result) { value = result[0]; }

So, make sure to write the console.log part inside the callback method, like this:

function (result) { 
    value = result[0];
    console.log('value =', value);
}