Odoo 18: How to Trigger JS Functions from Menu Items
By Braincuber Team
Published on February 6, 2026
Standard Odoo menu items typically load a List View, Form View, or Dashboard. But what if you want a menu item to trigger an immediate action, like cleaning the cache, running a diagnostic script, or popping up a custom wizard?
In this guide, we will build a "System Health Check" menu item. When clicked, it won't open a page; instead, it will execute a JavaScript function that simulates a system scan and displays a toast notification to the user.
The Secret Sauce:
- ir.actions.client: The bridge between the database (XML) and the frontend (JS).
- tag: The unique identifier that acts as the handshake key.
Step 1: Define the Client Action
First, we create the ir.actions.client record in XML. This action tells Odoo, "When triggered, look for a JavaScript component registered with the tag system_health_check."
System Health Check
system_health_check
Step 2: Create the Menu Item
Next, we create the menu item and link it to the action we just created.
Step 3: The JavaScript Logic (OWL)
Now for the fun part. We create a JavaScript file that registers the action. We'll use the notification service to show feedback.
/** @odoo-module **/
import { registry } from "@web/core/registry";
import { useService } from "@web/core/utils/hooks";
import { Component, onWillStart } from "@odoo/owl";
class SystemHealthCheck extends Component {
setup() {
super.setup();
this.notification = useService("notification");
this.action = useService("action");
// Run logic immediately upon component mount
this.runCheck();
}
async runCheck() {
this.notification.add("Initiating Diagnostics...", { type: "info" });
// Simulate a delay (e.g., API call)
await new Promise(resolve => setTimeout(resolve, 2000));
this.notification.add("System Healthy! All services operational.", {
type: "success",
sticky: false
});
// Optional: Redirect back to dashboard after running
this.action.doAction({
type: 'ir.actions.act_window_close'
});
}
}
SystemHealthCheck.template = "base.EmptyTemplate"; // No UI needed
// Register the action with the tag name from XML
registry.category("actions").add("system_health_check", SystemHealthCheck);
Notice we use base.EmptyTemplate. Since this action is purely functional (a script runner), we don't need to render HTML.
Conclusion
By decoupling the menu item from a specific view, Odoo allows you to build powerful, app-like experiences. Whether it's a quick toggle, a background sync, or an interactive wizard, ir.actions.client is your gateway to full frontend control.
Building a Custom Odoo App?
Unlock the full power of the OWL framework. Our experts can build custom client actions and widgets tailored to your workflow.
