The “When View” property allows controlling the visibility of an action based on the current view.
For example, let’s create a custom action that will display the extended price of an order detail. This action will be available on editForm1 and grid1 by default. Let’s prevent the action from being displayed on grid1 by using When View property.
Creating the Action and Business Rule
Start the Project Designer. In the Project Explorer, switch to the Controllers tab. Right-click on OrderDetails / Actions / ag3 (ActionBar) – New node, and press New Action.
Assign the following values.
Property | Value |
Command Name | Custom |
Command Argument | ShowExtendedPrice |
Header Text | Extended Price |
Press OK to save. Right-click on OrderDetails / Business Rules node, and press New Business Rule.
Use the following configuration:
Property | Value |
Type | JavaScript |
Command Name | Custom |
Command Argument | ShowExtendedPrice |
Phase | Execute |
Script | var extendedPrice = [UnitPrice] * (1 - [Discount]) * [Quantity];
alert(String.localeFormat('{0:c}', extendedPrice));
|
Press OK to save.
On the toolbar, press Browse. Navigate to the Order Details page. The Extended Price button will be present on the action bar. When you select a row and activate the button, the extended price will be displayed in an alert.
Select a record – the action will also be available on editForm1.
Note that the action is not available on createForm1. This is because the When Last Command Name property of the action is blank (which is equivalent to “Select”). View createForm1 is activated by triggering the “New” action, resulting in the Extended Price action being hidden.
Specifying “When View”
Let’s restrict display of the Extended Price action to editForm1 using the When View property.
In the Project Explorer, double-click on OrderDetails / Actions / ag3 (ActionBar) – New / a100 – Custom, ShowExtendedPrice | Extended Price action node.
Change the When View property:
Property |
New Value |
When View |
editForm1 |
Press OK to save.
Viewing the Results
On the toolbar, press Browse. Navigate to the Order Details page. Note that the action is no longer displayed in grid1.
Select a record. The action will be available in editForm1.