This question has been flagged
5 Replies
4565 Views

Hi All,

Please am stuck with this, may be because i 'm not realy good in js

in the pos module i need to add a var to a model domain

but with an rpc query the response is "asynchrounously retrieved" i searched for days now and am not able to found the right way to get the variable and use it.

rpc.query({
model: 'product.product',
method: 'custom_funct_for_js',

}).then(function(result){
everybody saing //do_something or console.log(result) but please guys i need the result out of here please
});

in the source code and in plugins i found this kind of exemple

return afunctionname : function(){
        var myvar = 0;
return rpc.query({
model: 'product.product',
method: 'custom_funct_for_js',

}).then(function(result){
                myvar = result
but no way it's still async
});
        return myvar;
});


Any clue or solution for this, may be a tutorial

Thx in advance


Avatar
Discard
Best Answer

look at this example, you have to add     {async: false}



var params = {
     model: 'pos.order,
    method: 'your method',
     args: [val],
};

var num = 0; return rpc.query(params, {async: false}).then(function(res) {     num+=res; });
console.log(num);
Avatar
Discard
Best Answer

I think you can pass the result to another function ,so that you can use it from there..Or you can add that variable to self.variable_name,

where self = this;

Avatar
Discard
Best Answer

same issue i'm getting.

Have you find a way to do it?

Please replay back...

I am searching solution for this from long days...

 

Avatar
Discard
Best Answer

Hello All, 

For the above, you describe the problem, Try the solution returns the function from the rpc query. Like,

return afunctionname : function(){
        var myvar = 0;
return rpc.query({
model: 'product.product',
method: 'custom_funct_for_js',

}).then(function(result){
                myvar = result
            return myvar;
});
});
Avatar
Discard
Best Answer

Hello,


I've got exactly the same need. 


Have you find a way to do it?


Thanks in advance

Avatar
Discard