Sunday, December 30, 2012
Changing Values on Edit

Client-side business rules allow changing the value of a field without having to save it to the database. This way, the user can either approve the value, change it, or leave the original data intact.

Let’s add 7 days to the Order Date of an order when a user starts editing.

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

Creating a new business rule for Orders controller.

Assign the following values:

Property Value
Type JavaScript
Command Name Edit
Phase After
Script
var d = [OrderDate];
if (this.dataView().get_isEditing() && d != null) {
    d.setDate(d.getUTCDate() + 7);
    d.setHours(0);
    [OrderDate] = d;
}

The business rule will get the current date value of OrderDate, add 7 days, and assign the value.

Press OK to save. On the toolbar, press Browse. Navigate to the Orders page. Note the Order Date of a specific record.

Highlighting an order record and noting the Order Date.

Start editing the the record. The Order Date will be moved forward by 7 days from the original value.

When the order is edited, the Order Date is moved forward by 7 days.

If the user presses Cancel at this time, the Order Date will not be changed. If the user saves the record, the new value will be applied.

Order record with new order date.