When creating a new order, the order date should default to the current date.
There are three types of business rules that can be used for this purpose. Choose any one of the suggested implementations below.
SQL Business Rule
Switch back to the Project Designer. In the Project Explorer, open the Controllers tab. Right-click on Orders / Business Rules node, and press New Business Rule option.
Specify the following values:
|Property ||New Value |
|Type ||SQL |
|Command Name ||New |
|Phase ||Execute |
set @OrderDate = getdate()
Press OK to save the business rule. Press Browse in the top left corner, and wait for the page to load. Navigate to Order Form, and create a new order. Select a customer and employee. You will see that the current date has been inserted into the Order Date field.
Code Business Rule
C# or Visual Basic may be used as an alternative to SQL.
Switch back to the Project Designer.
If you have implemented the business rule above, then delete it. In the Project Explorer, right-click on Orders / Business Rules / New (SQL / Execute) – r100 node, and press Delete.
Create a “code” business rule with the following properties:
||C# / Visual Basic
Press OK to save.
Code business rules cannot be directly edited using the Project Designer, and do not exist until the project has been regenerated.
On the toolbar, press Browse to regenerate the project.
When complete, right-click on Orders / Business Rules / New (Code / Execute) – r100 node, and press Edit Rule in Visual Studio.
The rule file will be opened in Visual Studio. The entire class definition and parameters of the business rule method are already defined. Replace the body of the rule with the UpdateFieldValue method:
public partial class OrdersBusinessRules : MyCompany.Data.BusinessRules
public void r100Implementation(
Partial Public Class OrdersBusinessRules
Public Sub r100Implementation( _
ByVal orderID As Nullable(Of Integer),
ByVal customerID As String,
ByVal customerCompanyName As String,
ByVal employeeID As Nullable(Of Integer),
ByVal employeeLastName As String,
ByVal orderDate As Nullable(Of DateTime),
ByVal requiredDate As Nullable(Of DateTime),
ByVal shippedDate As Nullable(Of DateTime),
ByVal shipVia As Nullable(Of Integer),
ByVal shipViaCompanyName As String,
ByVal freight As Nullable(Of Decimal),
ByVal shipName As String,
ByVal shipAddress As String,
ByVal shipCity As String,
ByVal shipRegion As String,
ByVal shipPostalCode As String,
ByVal shipCountry As String)
Save the file. If you create a new order in the web application, the Order Date will be populated with the current date.
If you created one of the above business rule implementations, delete it now.
Create another business rule with this configuration:
[OrderDate] = new Date();
Note that the business rule must execute after the command “New”, because the record is not instantiated on the client until after the command is executed by the application framework on the server.
Save the file. The business rule will work as shown in the illustration at the top.