Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
1 Vastaa
721 Näkymät

I'm trying to develop a module in Javascript and I try to generate rpc calls to query odoo database. I'm trying to do some calls from differents functions like that "obtener_id_empleado" and I'm trying to return the result to the main function but I always obtain undefined. Why?


In the ​console.log(result) I obtain an array of database data, but after the return and the assignment in console.log(empleado) I obtain undefined. Why? 



willStart: function () {

            var self = this;

​   var empleado = 0;

            empleado = this.obtener_id_empleado();

            console.log(empleado);  

 },


obtener_id_empleado: function(){

​rpc.query({

                model: 'hr.employee',

                method: 'search_read',

                args: [[['user_id', '=', this.getSession().uid]], ['name','id']],

​       context: session.user_context,

            })

            .then(function(result) {

​console.log(result);

​return result;

            });

},


Thanks

Avatar
Hylkää
Tekijä Paras vastaus

Any news?

Avatar
Hylkää

It appears like you are running into a typical problem with JavaScript asynchronous programming. When you call this.obtener_id_empleado(), it executes the function without waiting for the promise to resolve since the rpc.query method returns a promise. The reason you're seeing undefined is because empleado is assigned the promise itself rather than the returned result. https://geometrydash2.com/

Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
0
heinäk. 25
295
1
heinäk. 25
5074
0
heinäk. 25
640
0
kesäk. 25
710
1
kesäk. 25
876