In your widgets code you can simply call the execute() method on the action.
You will receive the action as a prop (this.props.onScanAction). To be sure the action is available you can check the canExecute (this will check if the user can access the action like open page, call nanoflow etc). If you want to make sure the action is not triggered twice (because of double click for instance) you can check the isExecuting boolean on the action. These are all default properties of the Action in a widget. Full example below:
if(this.props.onScanAction.canExecute && !this.props.onScanAction.isExecuting){
this.props.onScanAction.execute();
}
You can use the “executeAction “ from the module “piw-utils”.
You can find it in the standard Mendix widget https://github.com/mendix/widgets-resources in the folder “packages/tools”.
Either you duplicate it in your project as a component like below, or create a dependency.
import { executeAction } from "./components/piw-utils/src/functions";
//Trigger action on onScan event (microflow or nanoflow)
executeAction(this.props.onScanAction);