Fields


Fields are named variables in which 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 Documents" in Chapter 4.

Outlook provides a large number of built-in fields, but you'll often need to add custom fields for your application. Outlook allows you to add 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 field that holds the result of a formula that calculates a value using data from other Outlook fields.

Creating Custom 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 own fields. To view the Field Chooser, select a table view in your folder (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 choose Field Chooser, as shown in Figure 3-9.

click to expand
Figure 3-9: Selecting the Field Chooser from the shortcut menu

To create a new field, click the New button, enter a name and data type for the field, and then select the appropriate format. Following is a list of possible data types for fields in Outlook and the type of formatting these fields support:

  • Text     This field type can hold text strings or a combination of text strings and numbers , such as in a mailing address. It can hold up to 255 characters .

  • Number     This field type is for numeric data (except numbers that represent currency) and for mathematical calculations. You can format this field with one of nine different formats, such as a scientific notation format (125.3E+03).

  • Percent     This field type stores numeric data that is a percentage. You can choose from four formats. For example, you can set how many decimal places to show in the percentage.

  • Currency     This field type stores numeric data that represents a currency value. You can format this data type to show or hide the cents portion of the currency ”for example, $5,232 or $5,232.10.

  • Yes/No     This field stores data that holds one of two values in a pair of values. You can select Yes/No, True/False, On/Off, or a check box icon in your Outlook view.

  • Date/Time     This field stores date and time data. You can format this field using a number of standard formats, as in these examples: Monday, May 05, 2003 7:00 AM; 5/5/03 7:00 AM; May 5, 2003; or Mon 5/5/2003.

  • Duration     This field is for numeric time data that represents an elapsed time value. You can expose the data in several formats, such as 12h or 12 hours. The value in this field is automatically calculated when the data should be displayed as days, hours, or minutes. For example, if you set the format for this field as "12 hours" and you enter .25 , Outlook displays 15 minutes. You can also set the format so Outlook takes into account only working hours. (By default, this means an 8- hour day, but you can customize the default.)

  • Keywords     This data type holds multiple text values (which are separated by commas) and is similar to the Categories field in Outlook. When you create custom views, you can use keywords to filter the items displayed.

  • Combination     This data type holds a combination of fields and literal text. You can show each field or only the first nonempty field. The fields created with this data type are read-only in Outlook. For more information on creating combination fields, see the next section, "Creating Combination Fields."

  • Formula     This data type holds the results of formulas you create. You can use the Microsoft Visual Basic expression service that is built into Outlook to create functions and operators for your formula. The fields created with this data type are read-only in Outlook. For more information on creating formula fields, see the section titled "Creating Formula Fields" later in this chapter.

  • Integer     This data type holds nondecimal numeric information. You can customize the format to be only numbers, such as 3,332, or to be "computer" numbers formatted as kilobytes, megabytes, and gigabytes.

Creating Combination Fields

You can create a combined value, or combination field , by concatenating literal strings and the values from one or more Outlook fields. Combination fields are useful when you have many types of fields and want to create a single field that combines them. 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 create a combination field from two fields and a text fragment:

  1. In your Inbox, right-click on a column in your view, choose Field Chooser, and click New. (If the Inbox pane is not wide enough to show multiple columns , you might not see the Field Chooser in the shortcut menu.)

  2. Enter a name for the field, such as My Follow-Up Field , and select Combination as the type of field.

  3. Click Edit.

  4. You have the choice to join fields and text fragments to create a combination field or show only the first nonempty field and ignore all the subsequent fields. Select the Joining Fields And Any Text Fragments To Each Other option.

  5. In the Formula text box, type Need .

  6. Click the Field button, point to Frequently-Used Fields, and then click Follow Up Flag.

  7. In the Formula text box, type By .

  8. Click the Field button, point to Frequently-Used Fields, and then click Due By.

  9. Click OK twice.

  10. Drag and drop this new field from the Field Chooser onto your Inbox column headings. You should see something similar to Figure 3-10.

    click to expand
    Figure 3-10: Two fields combined with string literals to create a single combination field

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. 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 in this property when designing or saving the document, the Author property can 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 these steps to create the combination field that shows the first nonempty field:

  1. Go to the Document Library folder you created, and open the Field Chooser.

  2. Click New.

  3. Type a name for the field, such as Document Author .

  4. Select Combination as the field type.

  5. Click Edit.

  6. Select the option named Showing Only The First Non-Empty Field, Ignoring Subsequent Ones.

  7. Click the Field button, point to All Document Fields, and then click Author.

  8. Click the Field button, point to All Mail Fields, and then click From.

  9. Click OK twice.

  10. Drag and drop your new field from the Field Chooser onto the view column headings. You should see a view similar to the one shown in Figure 3-11.

    click to expand
    Figure 3-11: Combination fields that show the first nonempty value from multiple Outlook fields

Creating Formula Fields

In formula fields, you use functions to calculate values from both standard and custom fields. These values are then stored inside the formula field. For example, you can use a formula field to calculate the total of an expense report or a person's wage based on the number of hours worked multiplied by his 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 Field and Function buttons to select the fields and functions you want to use in your formula. Outlook parses your formula and checks it for syntactical errors.

Formula fields do have a few 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 takes to process them. Second, Outlook 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 3-12 shows a custom formula field.

click to expand
Figure 3-12: A custom formula field in an Outlook view
  1. In the Field Chooser, click New.

  2. Type a name for your new field, such as Days since received .

  3. Select Formula from the Type drop-down list.

  4. Click the Edit button.

  5. In the Formula box, type all of the following on the same line:

     IIF(DateDiff("d",[Received],Now())>=7, DateDiff("w",[Received],Now()) & " week(s) ago", DateDiff("d",[Received],Now()) & " day(s) ago") 
  6. Click OK twice.

  7. Drag and drop the new field onto your view column headings. You should see the field calculate automatically. If the item was received within one week, the field will display the amount in days. If the item was received more than a week ago, the field will display the amount in weeks.

Using Custom Fields in Filtered Replication

As you learned in Part I of this book, Outlook and Exchange Server support synchronizing items with an offline store. By default, Outlook synchronizes all items between the server and your offline database. But what if you don't want to synchronize all the items? Outlook offers the ability to synchronize subsets of information ”a process known as filtered replication . You select the parameters ”based on either built-in or custom fields ”that Outlook will use to filter the synchronized items.

Follow these steps to set up filtered replication for the Account Tracking application:

  1. To create the filter criterion, add a custom property to the Account Tracking application. Select the Account Tracking folder within the Favorites folder, right click on the column headers, and select the Field Chooser.

  2. In the Field Chooser, click New.

  3. In the Name text box, type txtAccountSalesRep , and then select Text as the type.

  4. Click OK.

  5. From the File menu, select Folder and then Properties For Account Tracking.

  6. Click on the Synchronization tab.

  7. Click the Filter button. If the filter button is not enabled, set the folder as an offline folder by using the Send/Receive settings.

  8. In the Filter dialog box, click on the Advanced tab.

  9. Click the Field button, point to User-Defined Fields In Folder, and click txtAccountSalesRep.

  10. From the Condition drop-down list, select Is (Exactly). In the Value text box, type the name of a user of the Account Tracking application.

  11. Click the Add To List button to add your criteria. Your screen should look something like Figure 3-13.

    click to expand
    Figure 3-13: The Filter dialog box, showing synchronization criteria for the Account Tracking application

  12. Click OK to close the filter dialog, click OK to acknowledge the message regarding the next synchronization and, finally, click OK to close the folder properties sheet. Now only the items meeting your criteria will be synchronized with your offline database.

Figures 3-14 shows the Account Tracking folder before filtered replication is set. Figure 3-15 shows the same folder after filtered replication. As you can see, only a subset of the information in the folder is available to the client off line.

click to expand
Figure 3-14: The Account Tracking folder before filtered replication
click to expand
Figure 3-15: The Account Tracking folder after filtered replication



Programming Microsoft Outlook and Microsoft Exchange 2003
Programming MicrosoftВ® OutlookВ® and Microsoft Exchange 2003, Third Edition (Pro-Developer)
ISBN: 0735614644
EAN: 2147483647
Year: 2003
Pages: 227
Authors: Thomas Rizzo

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net