Monday, March 5, 2012
Orders: Configuring Lookup Fields

When creating a new order, the first item that will be entered will probably be the customer. Due to the denormalized nature of Northwind database, the customer information is stored in the table Customers, and the Orders table references a customer via a foreign key field CustomerID. Upon creating a new order, it would be convenient if the user were prompted to either select an existing customer or create a new one. When the customer is selected, the shipping information should be copied from the customer to the order.

Switch back to the Designer, open grid1 view under Order Form page, expand CustomerID data field, and double click on the CustomerID field.

CustomerID field in Code On Time Designer

Enter the following settings for CustomerID:

Property Text
Data Value Field CustomerID
Data Text Field CompanyName
Copy

ShipName=ContactName
ShipAddress=Address
ShipCity=City
ShipRegion=Region
ShipPostalCode=PostalCode
ShipCountry=Country

Search on Start True
Activate If Blank True
Lookup window description Select a customer.

CustomerID Lookup configuration in Code On Time Designer

Press OK to save the field.

When the customer has been selected, we’d want the application to prompt the user to select the employee handling the order. To make this part easier, let’s add photos of each employee in the lookup.

Open EmployeeID data field, and double click on EmployeeID field.

EmployeeID field in Code On Time Designer

Change the following settings for EmployeeID:

Property Text
Activate If Blank True
Lookup window description Select an employee.

EmployeeID Lookup configuration in Code On Time Designer

Press OK to save the record.

Switch to the Controllers tab at the bottom of the Explorer, open Employees controller, open Views, and right click on grid1. Press New Data Field.

New Data Field for Employees controller

Select a Field Name of “Photo”, and save the data field.

New Photo Field in Employees Controller

In the upper left corner, press Generate, and wait for the application to load. Navigate to the Order Form page, and press New Orders on the action bar. You will be prompted to select a customer.

CustomerID Lookup showing filtering and advanced search in Code On Time Preview

When you search for and select a customer, you will then be prompted to select an employee. You can see the photo for each employee as well.

Employee ID Lookup for Order Form

Select the employee, and you will see that the shipping fields have been populated from the selected customer.

New Order Form in Code On Time Preview