Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
6214 Visualizzazioni

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
Abbandona
Risposta migliore

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
Abbandona
Post correlati Risposte Visualizzazioni Attività
2
dic 22
3136
1
mag 21
5448
1
mar 15
4231
0
mar 15
4008
2
mag 24
1653