Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
6201 Zobrazení

Hi,

I am trying to implement additions to a module using OWL. 

I went along with this article and managed to get to the stage that they describe:

https://www.oocademy.com/v14.0/tutorial/introduction-to-owl-87

Now I would like to add a button, which when pressed will open a different view. Or in general, add a button which when pressed will call an action which I have already defined outside of the js and owl templates, but rather in the view xml files of the module.

Wasn't able to do this, any help would be greatly appreciated.

Thanks.

Avatar
Zrušit
Nejlepší odpověď

Hi Alon,

To call an action using Owl.js, you can follow this approach:

import { useService } from "@web/core/utils/hooks";

export class MyComponent extends Component {
    setup() {
        super.setup();
        this.action = useService("action");
    }

    async createApp() {
        console.log('Creating app...');
        try {
            const result = await this.action.doAction({
                type: "ir.actions.client",
                tag: "action_tag",
            });
            console.log('Action result:', result);
        } catch (error) {
            console.error('Error:', error);
        }
    }
}

In this code:

  • We import the useService hook from Owl.js to access the action service.
  • Inside the setup method, we initialize the this.action property with the action service.
  • The createApp method is defined to trigger the action. It is marked as async to handle asynchronous actions.
  • We use this.action.doAction to execute the desired action. The action configuration includes its type and tag.
  • We log the result of the action, and handle any errors that may occur during execution.
  • You can further extend this code to handle the action result or any additional logic as needed.

Hope it helps

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
2
pro 22
3119
1
kvě 21
5440
1
bře 15
4223
0
bře 15
4007
2
kvě 24
1648