Skip to Content
Menu
This question has been flagged
3 Replies
1283 Views

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
Discard
Author

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
Discard
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
Discard
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
Discard

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 Replies Views Activity
0
Mar 25
362
1
Jun 23
1443
1
May 23
1349
1
Dec 22
2639
1
Oct 22
3488