Fields are named variables where Outlook stores the data for your application. A number of built-in fields store default information. These built-in fields are associated with folders and their default content type. For example, in a Contacts folder, built-in fields include First Name, Last Name, Mailing Address, and Primary Phone. In your Inbox, built-in fields include From, To, Subject, and Message. Outlook also supports Office document properties as fields. For more information on using Office document properties as fields, see the section titled "Extending Functionality with Office Document Forms" in Chapter 5.
Outlook provides an extensive amount of built-in fields, but there will be many times when you need to add custom fields for your application. Outlook fully supports this capability and allows you to add custom fields to any folder. Your custom fields can range from a simple data type, such as a text field, to a complex data type, such as a formula field that includes a formula to calculate the value of the field from other Outlook fields.
The easiest way to create and delete custom fields in Outlook is to use the Field Chooser. The Field Chooser allows you to see both the built-in Outlook fields and your custom fields. The easiest way to access the Field Chooser is to select a table view in your folder, such as any of the default Outlook views that begin with the word By. For example, in your calendar, you can switch your view to the By Category view. After selecting a table view, right-click on the column headings and select Field Chooser from the context menu, as shown in Figure 4-9.
Figure 4-9 Select the Field Chooser from the context menu for a table view.
To create the new field, click the New button, enter a name and data type for the field, and select the appropriate format. The following is a list of possible data types for fields in Outlook and the type of formatting these fields support:
You can combine values from other fields with literal strings to create a new field, called a combination field. Combination fields are useful when you have many different types of fields and want to create a single field that combines them all. You can also use a combination field when you have multiple fields that hold conflicting data and you want to display only one of the fields in your form. Here's how you would create a combination field from two fields and a text fragment:
Use a combination field when you want to expose a primary value for a specific field but also need the option to expose a field that holds a secondary value if the primary value is not available. If the primary value is available, you do not want to display the secondary value. For example, in our Document Library application, users can drag and drop Office documents into the public folder. Outlook can expose the properties of these office documents as fields. In the Outlook view, we want to expose the document author, but because users are not required to fill this property in when designing or saving the document, the Author property could be left blank. If the Author property is left blank, we want to use the From field in Outlook to display the name of the user who dragged and dropped the document into the folder. Follow the steps below to create the combination field that shows the first nonempty field.
Figure 4-10 Two different fields are combined to create a single combination field.
Figure 4-11 You can use combination fields to show the first nonempty value from multiple Outlook fields.
Formula fields allow you to use functions to calculate values from both standard and custom fields. These calculated values are stored inside of the formula field. Use formula fields when you need to calculate the value of one field based on other fields in your application. For example, you can use a formula field to calculate the total of an expense report or a person's wage based on the amount of time they worked multiplied by their hourly rate. Outlook makes creating formula fields quite easy by offering a simple interface for field selection and by displaying a list of all possible formulas and required inputs. You can use the provided Field and Function buttons to quickly select the fields and functions you want to use in your formula. Outlook will automatically parse your formula and check it for syntactical errors.
Formula fields do have some performance implications. First, Outlook has to process formula fields whenever values change in the application. The more complex you make your formulas, the longer Outlook will take to process them. Second, Outlook automatically recalculates formula fields whenever the current view changes. Third, Outlook does not allow you to sort, group, or filter views by using formula fields.
Follow these steps to create a formula field that displays the amount of time elapsed since an item was received. Figure 4-12 shows a custom formula field.
IIF(DateDiff("d",[Received],Now())>=7, DateDiff("w",[Received],Now()) & " week(s) ago", DateDiff("d",[Received],Now()) & " day(s) ago") |
Figure 4-12 A custom formula field in an Outlook view.
As you learned in Part I, Outlook and Exchange Server support synchronizing items offline. By default, Outlook synchronizes all the items from the server to your offline database. But what if you don't want to synchronize all the server items offline? As you learned in Chapter 2, Outlook offers the capability to synchronize subsets of information, called filtered replication. You select the parameters—either built-in or custom fields—that Outlook will use to filter the synchronized items. To set up filtered replication, follow these steps:
Figure 4-13 The Filter dialog box, showing synchronization information for the Account Tracking application.
Figure 4-14 shows the folder before setting filtered replication and after setting filtered replication. As you can see, a subset of the information in the folder is available to the client offline.
Figure 4-14 The Account Tracking folder before filtered replication, and the Account Tracking folder after filtered replication. Notice how a subset of items are synchronized offline.