You use actions to define work that a user or API can execute in a running MDriven application, whether that work applies to the application, an object, or the current ViewModel.
Choose the action scope
An action's scope determines the context available when it runs and where the action can be used. Define the action at the narrowest scope that fits the behavior.
| Action type | Use it when | Context and availability | Example |
|---|---|---|---|
| Global action | The user must be able to start work that is not tied to one displayed object or one ViewModel. | Available as an application-level or main-menu action. | Provide a command that opens an application-wide workflow. |
| Class action | The behavior belongs to an instance of a model class and should be available wherever that class is shown. | The context is the class object. Use self to refer to that object. A class action cannot use ViewModel vCurrent or vSelected variables.
|
On an Order object, define an action that performs work for that order. The same action can be available in every view that shows an Order.
|
| ViewModel action | The behavior depends on what the user currently sees, focuses, or selects in one ViewModel. | The action belongs to one ViewModel. Use vCurrent_ variables for the current focus and vSelected_ collections for multiple selected grid items in the corresponding ViewModel nesting.
|
In an order-list ViewModel, act on the row currently selected by the user. |
Rule of thumb: make an action a class action when its logic is based on the object itself. Use a ViewModel action when the logic needs the current view state or selection. This makes class behavior reusable across views and keeps view-specific behavior with the ViewModel.
Define an action
- Identify what starts the work. For example, a user may choose a menu command, click a button, drag an object, or perform a swipe.
- Choose the scope from the table above.
- Define when the action is available with its enable expression.
- Define what the action does with its execute expression. Action expressions use OCL and EAL as applicable.
- Expose the action in the relevant user interface, or invoke it from another action or API.
For class actions in MDriven Designer, open the class actions from the diagram by selecting the small arrow at the top of the class. You can also right-click the class header and select Add Class action. The action editor shows the enable and execute expressions in the class-object context.
Use camel case for a class-action name, such as ApproveOrder. MDriven splits camel case into words for presentation until you set a different presentation.
For the fields and settings in the action-definition UI, see Documentation:Actions Editor.
Run and present actions
You can make an action available through framework-provided menus, opt it in or out for a view, or place a button on a view that refers to the action. A button can also contain EAL directly in the ViewModel instead of referring to a separately defined action. Use a named action when the behavior needs a reusable definition; use view-local EAL only when the behavior belongs only to that ViewModel.
Actions can also be invoked from EAL. Before invoking an action, you can test whether it can execute.
Some interactions can trigger an action without a conventional button:
- A drag or drag-drop interaction can execute a drag action.
- A mobile swipe can execute an action.
- A periodic action in a ViewModel can run at an interval configured in the view.
- A server-side action can run on a schedule in MDrivenServer. The ViewModel defines the information scope to act on and the EAL code to execute. For example, a scheduled action can run every minute, find the relevant information in its ViewModel scope, test a condition, and execute its action.
Use standard actions for common view operations
Standard actions provide common view operations rather than custom EAL. In the Global actions view, select Ensure Std Actions to create the default actions.
| Standard action | Effect |
|---|---|
| Save | Saves changes in the current view. |
| Cancel | Cancels changes in the current view. |
| Refresh | Refreshes data from the server. |
| Undo | Reverses changes in the current view. |
| Redo | Reapplies changes reversed by Undo; it has no effect until Undo has been used. |
| Exit | Exits the program when the current execution environment supports exit, such as WPF. |
If Save or Cancel is missing in a web-browser application, use Ensure Std Actions in the Global actions view. See Documentation:Standard actions for the full standard-action guidance.
Table limitation in the web client
When you place actions in a web-client table, class actions and actions with EAL in a ViewModel work with their normal enabled and disabled behavior. ViewModel/context actions appear disabled in tables. Plan table commands accordingly; use a class action or an action with EAL when that behavior meets the requirement. See Documentation:Web client actions in tables.
Related configuration
Action availability and presentation are separate decisions. After defining the action, configure whether it is shown for a view and how it acts for the current context. See Documentation:Turnkey session 3: Opting out actions and Documentation:Act as For Actions.
