Skip to Content
Menú
This question has been flagged
3 Respostes
1406 Vistes

I have opened the wizard from JS , now i need the wizard to return value to JS.


Code
async openWizard() {
return new Promise((resolve) => {
var value = this.actionService.doAction(
{
type: "ir.actions.act_window",
res_model: "employee_link",
view_mode: "form",
view_type: "form",
views: [[false, "form"]],
target: "new",
},
{
onClose: () => resolve(value),
}
);
​console.log(value)
});
},

on cosole it is printing :
    [[Prototype]]: Promise
    [[PromiseState]]: "fulfilled"
    [[PromiseResult]]: undefined
Avatar
Descartar
Autor

Thanks, but how can I store the wizard record ID mentioned in the answer?

const recordId = this.wizardRecordId; // Assuming you store the wizard record ID somewhere

Best Answer

I encountered a similar problem where I was getting "undefined" when trying to retrieve the result from a wizard in Odoo. I resolved it by using a Promise and capturing the result within the onClose callback. This ensured that I had the correct value after the wizard closed. If you can provide more details about your specific setup, I might be able to assist you further.

Avatar
Descartar
Best Answer

Hi,

To resolving the problem of promise, we need to use async and await in our code to get the data.

Use the following code as a reference to do the same for your problem:

async openWizard() {

    return new Promise((resolve) => {

        this.actionService.doAction(

            {

                type: "ir.actions.act_window",

                res_model: "employee_link",

                view_mode: "form",

                view_type: "form",

                views: [[false, "form"]],

                target: "new",

            },

            {

                onClose: async () => {

                    // Fetch the data you want to return here

                    const linkData = await this._fetchWizardData();

                    resolve(linkData);

                }

            }

        );

    });

},


// Helper function to fetch data from the wizard

async _fetchWizardData() {

    const recordId = this.wizardRecordId; // Assuming you store the wizard record ID somewhere

    // Here you can write the logic to get the data, like an orm call.

    })    // Return the data

}


Hope it helps.

Avatar
Descartar
Best Answer

Hello Jayaram,


To identify the issue that you have mentioned. let's update the code.

However, the value is being logged as undefined because it is not set before the resolve call. 

You need to update value within the onClose callback to capture the necessary information when the wizard closes.

// Code In Comment //

I Hope this information proves helpful to you.

Thanks & Regards,

Email:   odoo@aktivsoftware.com           

Skype: kalpeshmaheshwari 

Avatar
Descartar

Code:

async openWizard() {
return new Promise((resolve) => {
this.actionService.doAction(
{
type: "ir.actions.act_window",
res_model: "employee_link",
view_mode: "form",
view_type: "form",
views: [[false, "form"]],
target: "new",
},
{
onClose: (result) => {
var value = result; // Capture the result or value from the wizard
resolve(value);
},
}
);
});
}

Related Posts Respostes Vistes Activitat
0
de març 25
447
1
de juny 23
1564
1
de maig 23
1488
1
de des. 22
2821
1
d’oct. 22
3688