🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
MDrivenStart DefineUserActions
This page was created by Hans.karlsen on 2020-07-08. Last edited by Wikiadmin on 2026-07-29.

You can define user actions in MDriven Designer to let users open views or act on information, and you choose the action type by the context in which the action must be available.

A user action is an operation that a user can initiate in the application. MDriven provides three action scopes:

Action type Use it when Availability and context Example
Global action The user must be able to start a task without first selecting an object. Appears in the main menu. It commonly opens a ViewModel that is not rooted in one specific object. Open a Customer seeker so the user can search for a customer.
Class action The task acts on an instance of one class and should normally be available wherever that type of object is selected. Becomes available when the user selects an instance of the class for which the action is defined. The selected object provides the action context. On a selected Order, run an action that changes the order's state.
ViewModel action The task belongs to one particular view and depends on that view's current focus or selection. Is specific to one ViewModel. It does not use self; it receives view context through vCurrent_ variables and, for multi-selection in grids, vSelected_ collections. In an order list view, process the orders currently selected in the grid.

Choose the action type

Use the narrowest scope that matches the task:

  1. Ask whether the user needs to select an object before the task can start.
  2. If no object is required, define a global action. Global actions are main-menu actions and commonly open a seeker or browser ViewModel.
  3. If the task acts on one object instance and should follow that object's type throughout the application, define a class action. For example, an action for an Order should be available when an Order is selected, rather than being recreated separately in every Order view.
  4. If the task is meaningful only in one ViewModel, define a ViewModel action. Use its vCurrent_ and vSelected_ context to work with what the user is focused on or has selected in that view.

Typical use cases

Start a task from the main menu

Create a global action when a user begins by finding information rather than acting on a known object. For example, a Customer seeker lets the user filter a large customer set before opening a customer-specific view. A browser is another un-rooted view that shows all available instances of a class.

See Global actions for this action type.

Act on the selected object

Create a class action when the model type determines when the action is relevant. For example, if the user selects an Order, an Order action can act on that selected Order. This avoids having to declare the action separately for every place where an Order may appear.

The normal rule is to use a class action for an action on an object instance. If there are places where the action must not be available, configure the required opt-out rather than replacing the class action with repeated view-specific actions.

See Class actions for the class-action behavior and opt-out concept.

Act on a view's focus or selection

Create a ViewModel action when its meaning depends on one view. Unlike a class action, a ViewModel action has no self. MDriven supplies the current focus in variables whose names start with vCurrent_.

For example, in a grid nesting named Orders, use the corresponding vSelected_ collection when the user selects multiple orders and the action must process that selection. Use the corresponding vCurrent_ variable when the action applies to the current focused item instead.

See ViewModel actions for the available view context.

Design actions with the model

An action often invokes model behavior. Define that behavior as a method when appropriate:

  • A method with IsQuery=true has an OCL body and must not change data.
  • A method with IsQuery=false can use action-language statements to change data.

For example, an Order class action can invoke a non-query method when the action must update the selected Order. Keep the action scope aligned with the method's intended context: an Order-focused operation belongs on the Order class; a task driven by a particular view's multi-selection belongs in that ViewModel.

After defining or changing actions, validate the model. Validation runs when you save, and you can also run it manually. Resolve all errors before running the Prototyper or deploying the model; see Verify.

See also