Se rendre au contenu
Menu
Cette question a été signalée
1 Répondre
6188 Vues

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
Ignorer
Meilleure réponse

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
Ignorer
Publications associées Réponses Vues Activité
2
déc. 22
3103
1
mai 21
5438
1
mars 15
4213
0
mars 15
4002
2
mai 24
1646