Wednesday, January 2, 2013
Custom Business Rule for Duplicate Action

The default behavior of Duplicate action is to execute the New action and automatically copy values from the current row into the fields of the record. If it is necessary to change the default behavior, a custom business rule must be used.

A user can duplicate a customer using the Duplicate context menu option in Customers grid.

Duplicate context menu action for a row in Customers grid.

The create form will be opened. Fields will be populated using the values of the original record.

Duplicate causes the New Customers form to open with the same values as the original record.

Let’s add a business rule that will add an asterisk (*) to the Customer# field.

Start the Project Designer. In the Project Explorer, switch to the Controllers tab. Right-click on Customers / Business Rules node, and press New Business Rule.

Creating a new business rule for Customers controller.

Assign these values:

Property Value
Type JavaScript
Command Name New
Phase After
Script
[CustomerID] = [CustomerID] + '*';

Press OK to save. On the toolbar, press Browse.

Navigate to the Customers page. Activate the context menu for a row and press Duplicate.

Activating 'Duplicate' context menu option for a Customers record.

The Customer# value will be appended with an asterisk.

The 'CustomerID' field is appended with an asterisk.

This Duplicate action is only client-side. The data is only saved to the server when the user presses OK.

More complex duplication calculations that require database interaction can be implemented with the use of REST (Representational State Transfer) or with the use of SQL Business Rules.