CanExecuteAction lets you check whether an action in a named ViewModel nesting can run before you call ExecuteAction; use it when your OCL logic needs to branch on whether that action is currently available.
Syntax
selfVM.CanExecuteAction(nameofNesting, nameofAction) : BooleanThe operator returns a Boolean value:
| Result | Meaning |
|---|---|
true
|
The named action can be executed in the specified ViewModel nesting at this time. |
false
|
The named action cannot be executed at this time. |
Arguments
| Argument | Type | Description |
|---|---|---|
nameofNesting
|
String | The name of the ViewModel nesting that contains the action. |
nameofAction
|
String | The name of the action to check. |
Check an action before executing it
For example, a ViewModel has a nesting named OrderList and an action named ApproveOrder. Check whether the action can run:
selfVM.CanExecuteAction('OrderList', 'ApproveOrder')The expression returns true when ApproveOrder can run for OrderList. It returns false when it cannot run, for example when no order is selected or when a business rule prevents approval.
Use the result as a condition before executing the action:
if selfVM.CanExecuteAction('OrderList', 'ApproveOrder') then
selfVM.ExecuteAction('OrderList', 'ApproveOrder')
endifThis pattern avoids attempting to execute an action when it is not currently available.
Related operators
Use CanExecuteAction to determine whether an action can run. Use ExecuteAction to run the action after the check succeeds. CanExecuteAction concerns action availability within a nesting; it is different from canAccess, which evaluates whether an object can access a supplied ViewModel according to that ViewModel's access expression.
