You can use ExecuteAction in EAL or OCL to run a named ViewModel action in a specified nesting, including actions whose logic you want to reuse outside the original UI control.
What ExecuteAction does
ExecuteAction invokes the logic configured for a ViewModel action. It targets the action by the name of its ViewModel nesting and the name of the action (the action column).
Use it when an action already contains the process you need and another action or controller must trigger that same process. For example, an Order grid can expose an ApproveOrder action, and another process can invoke that action for the currently selected Order row rather than duplicate its approval logic.
Syntax
selfVM.ExecuteAction(nameofNesting, nameofAction)
| Argument | Type | Description |
|---|---|---|
selfVM
|
ViewModel context | The ViewModel from which you invoke the action. |
nameofNesting
|
String | The name of the ViewModel nesting that contains the action. |
nameofAction
|
String | The name of the action to run in that nesting. |
Both names are supplied as strings. They must identify the nesting and action that you configured in the ViewModel.
Execute an action
- Identify the ViewModel nesting that contains the target action. For example, use
Ordersfor an Orders grid nesting. - Identify the action name in that nesting. For example, use
vApproveOrder. - Call
ExecuteActiononselfVM, passing both names.
selfVM.ExecuteAction('Orders', 'vApproveOrder')
This executes the logic defined by vApproveOrder for the selected row in the Orders nesting.
Visibility and enablement
ExecuteAction runs the target action without regard to its visible or disabled expression. A disabled or hidden UI action can therefore still be invoked through ExecuteAction.
You are responsible for enforcing any conditions that must apply when the action is invoked from code. This distinction lets the UI and server-side or programmatic execution follow different rules when required, but it also means that a UI disable expression is not a safeguard for calls made through ExecuteAction.
Before invoking an action where execution depends on selection or business rules, use CanExecuteAction to determine whether the named action can be executed in the target nesting.
Example: reuse an Order approval action
Assume a ViewModel has:
- A nesting named
Orders. - An action in that nesting named
vApproveOrder. - A selected Order row.
Invoke the existing action logic with:
selfVM.ExecuteAction('Orders', 'vApproveOrder')
The call runs the logic configured for vApproveOrder on the selected Order. If no suitable row is selected, or if the process has conditions that must be met, check those conditions before making the call.
When to use it
Use ExecuteAction when:
- You need to reuse logic already defined in a ViewModel action.
- An action in one part of a ViewModel must trigger an action in a named nesting.
- A generic controller needs to start a process represented by a ViewModel action.
Do not rely on the target action's UI visibility or disabled expression to control programmatic execution.
