Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
1775 Lượt xem

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
Ảnh đại diện
Huỷ bỏ
Tác giả

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

Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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 

Ảnh đại diện
Huỷ bỏ

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);
},
}
);
});
}

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 3 25
659
1
thg 6 23
1938
1
thg 5 23
1882
1
thg 12 22
3236
1
thg 10 22
4041