Wednesday, August 1, 2012
Handling “Custom” Actions

Code On Time web applications can have “Custom” actions that trigger business rules.

For example, let’s implement a custom action on orders form to count the number of order details that belong to the order.

Creating Action

Start the Project Designer. In the Project Explorer, switch to the Controllers tab. Right-click on Orders / Actions / ag2 action group node, and press New Action.

New Action context menu option for action group in the Project Explorer.

Give this action the following properties:

Property Value
Command Name Custom
Command Argument CountOfOrders
Header Text Count of Order Details

Press OK to save the action.

Creating Business Rule

In the Project Explorer, right-click on Orders / Business Rules node, and press New Business Rule.

New Business Rule context menu option for Business Rules node in the Project Explorer.

Assign the following properties:

Property Value
Type SQL
Command Name Custom
Command Argument CountOfOrders
Phase Execute
Script
declare @CountofOrderDetails int

select distinct @CountofOrderDetails = count(ProductID)
from "Order Details"
where OrderID = @OrderID

set @Result_ShowViewMessage = 
    'This order contains ' +
    cast(@CountofOrderDetails as nvarchar) +
    ' order details.'

Press OK to save the business rule. On the toolbar, press Browse to generate the web app.

Navigate to the Orders page. Select an order – you will see the action Count of Order Details on the form.

Count of Order Details button displayed on the form.

Click on the Count of Order Details button, and a message will appear above the view displaying the count of order details.

When Count of Order Details is pressed, a message is displayed above the view.