Folder home pages are a feature in Outlook 2000 that enable you to link an HTML page to any folder in the Outlook environment. (You saw this capability in the Outlook Today feature discussed in Chapter 7.) Folder home pages support offline viewing capabilities, so you can request Outlook to synchronize an HTML file that is associated with a folder offline when a user synchronizes the folder. This ensures that your HTML page is available whether the user is working offline or online. We will look at two folder home pages in this chapter. One will use the Outlook View control.
The process of associating a folder home page with a folder is easy. Outlook 2000 provides a user interface for this connection, shown in Figure 10-1. You can access this Properties dialog box in Outlook 2000 by right-clicking on a folder and then choosing Properties.
Figure 10-1. Configuring a folder home page for a folder.
Since Outlook 2000 hosts Microsoft Internet Explorer in-frame, when a user clicks on the folder, your folder home page can appear directly inside the Outlook client. Furthermore, you can make the folder home page the default view for a particular folder. In the Web pages for your folder home pages, you might want to include instructions for using the folder, a way to mail the folder owner, or a listing of links related to that folder or to other folders.
You can also add script to the folder home page to access the Outlook object model. Figure 10-2 shows the first example of a custom folder home page (Contacts.htm) for the Account Tracking application.
Figure 10-2. The folder home page (Contacts.htm) for the Account Tracking application.
To test the folder home pages, you'll need a machine that has Outlook 2000 with the Visual Basic Scripting Support and Collaboration Data Objects components installed. Follow these steps to set up the first folder home page:
Set oDatabaseEngine = _ item.application.CreateObject("DAO.DBEngine.35") |
to
Set oDatabaseEngine = _ item.application.CreateObject("DAO.DBEngine.36") |
If you want the application to create sales charts and print account summaries, install Microsoft Excel.
The following shows the script for the folder home page (Contacts.htm) displayed in Figure 10-2:
<SCRIPT ID=clientEventHandlersVBS LANGUAGE=vbscript> '****************************************************** 'In-line code ' 'These lines of code are run when the browser reaches 'them while parsing the document. They set up the global 'variables that are needed throughout the application. '****************************************************** Set oApplication = window.external.OutlookApplication Set oNS = oApplication.GetNameSpace("MAPI") 'Change this to your location for the Account Tracking folder set oAccountFolder = oNS.Folders("Public Folders").Folders( _ "All Public Folders").Folders("Account Tracking") 'Set some global vars for the EntryIDs Dim arrTaskEntryIDs() Dim oTasks 'Restricted collection of Tasks Dim arrAccountEntryIDs() Dim oAccounts 'Restricted collection of Accounts '****************************************************** 'Sub CreateAccount ' 'This subroutine creates a new account info form and 'displays it for the user to fill in '****************************************************** Sub CreateAccount() set oAccount = oAccountFolder.Items.Add("IPM.Post.Account info") oAccount.Display() End Sub '****************************************************** 'Sub GetTask(lEntryID) ' 'This subroutine gets the task that the user clicked on 'in the HTML page and displays it. An index into an 'array of EntryIDs is passed to this subroutine. '****************************************************** sub GetTask(lEntryID) lTaskEntryID = arrTaskEntryIDs(lEntryID-1) for each oItem in oTasks if oItem.EntryID = lTaskEntryID then set otmpTask = oItem end if next otmpTask.Display() end sub '****************************************************** 'Sub GetAccount(lEntryID) ' 'This subroutine gets the account that the user clicked on 'in the HTML page and displays it. An index into an 'array of EntryIDs is passed to this subroutine. '****************************************************** sub GetAccount(lEntryID) lAccountEntryID = arrAccountEntryIDs(lEntryID-1) for each oItem in oAccounts if oItem.EntryID = lAccountEntryID then set otmpAccount = oItem end if next otmpAccount.Display() end sub sub Window_onLoad() '**************************************************************** 'All of the following lines are run when the HTML page is 'loaded '**************************************************************** 'Put the name of the folder in the bar txtFolder.innerHTML = oAccountFolder.Name & " Folder" '**************************************************************** 'Figure out the account tasks for the current user '**************************************************************** RestrictString = "" RestrictString = "[Message Class] = ""IPM.Task""" & _ " AND [Owner] = """ & oNS.CurrentUser.Name & """ AND _ [Complete] = FALSE" Set oTasks = oAccountFolder.Items.Restrict(RestrictString) oTasksCount = oTasks.Count 'Redim the EntryID array ReDim arrTaskEntryIDs(oTasksCount-1) strTaskList = "<TABLE Border=0 cellpadding=2 cellspacing=2 " & _ "class='calendarinfo'><TR><TD><strong><Font Size=2><U>" & _ "Account Name</u></STRONG></TD><TD> </TD><TD>" & _ "<STRONG><Font size=2><U>Task Name</U></FONT></STRONG>" & _ "</TD><TD> </TD><TD><STRONG><Font size=2><U>" & _ "(Due Date)</U></FONT></strong></TD></TR>" 'Count the tasks using counter counter = 1 oTasks.Sort "[ConversationTopic]", False For each oTask in oTasks boolOverDue = 0 if oTask.DueDate = "1/1/4501" then strDueDate = "None" else strDueDate = oTask.DueDate 'Check to see whether the task is overdue if DateDiff("d",CDate(strDueDate),Now) > 0 then boolOverDue = 1 end if end if if boolOverDue then 'Turn red strTaskList = strTaskList & "<TR><TD><FONT " & _ "COLOR='#FF0000'><STRONG>" & oTask.ConversationTopic & _ "</STRONG></FONT></TD><TD> </TD><TD>" & _ "<A HREF='' onclick=GetTask(" & counter & _ ");window.event.returnValue=false>" & oTask.Subject & _ "</a></TD><TD> </TD><TD><FONT " & _ "COLOR='#FF0000'>(<Strong>" & strDueDate & _ "</Strong>)</FONT><BR></TD></TR>" else strTaskList = strTaskList & "<TR><TD><STRONG>" & _ oTask.ConversationTopic & "</STRONG></TD><TD>" & _ " </TD><TD><A HREF='' onclick=GetTask(" & _ "counter & ");window.event.returnValue=false>" & _ oTask.Subject & "</a></TD><TD> </TD>" & _ "<TD>(<Strong>" & strDueDate & "</Strong>)<BR></TD></TR>" end if arrTaskEntryIDs(counter-1) = oTask.EntryID counter = counter + 1 next TaskList.innerHTML = strTaskList & "</TABLE>" '**************************************************************** 'Figure out which accounts the current user is a team member of '**************************************************************** 'Find accounts where this person is a team member. 'First restrict to only account items. RestrictString = "" RestrictString = "[Message Class] = "IPM.Post.Account info"" Set oAccounts = oAccountFolder.Items.Restrict(RestrictString) 'Now find accounts where this person is a team member numFound = 0 strCurrentUser = oNS.CurrentUser.Name numTotalRevenue = 0 strAccountHTML = "<table border=0 width=100% cellpadding=3 " & _ "cellspacing=0 ID='Home' style='DISPLAY: inline; " & _ "MARGIN-TOP: 12px'>" strAccountHTML = strAccountHTML & "<TR><TD " & _ "class='calendarinfo'><STRONG><FONT SIZE=2><U>Account Name" & _ "</U></FONT></STRONG></TD></TR>" RestrictString = "" RestrictString = "[Message Class] = ""IPM.Post.Account info""" & _ " AND [txtAccountConsultant] = """ & strCurrentUser & _ """ OR [txtAccountExecutive] = """ & strCurrentUser & _ """ OR [txtAccountSalesRep] = """ & strCurrentUser & _ """ OR [txtAccountSE] = """ & strCurrentUser & _ """ OR [txtAccountSupportEngineer] = """ & strCurrentUser & """" Set oAccounts = oAccountFolder.Items.Restrict(RestrictString) numFound = oAccounts.Count ReDim arrAccountEntryIDs(numFound) counter = 1 For Each oAccount in oAccounts set oUserProps = oAccount.UserProperties arrAccountEntryIDs(counter-1) = oAccount.EntryID 'Get the total revenue for the account for 1998 and 1999. 'Get the revenue and add it to the total. num1998Total = oUserProps.Find("form1998ActualTotal") num1999Total = oUserProps.Find("form1999ActualTotal") if num1998Total <> "Zero" then numTotalRevenue = numTotalRevenue + num1998Total end if if num1999Total <> "Zero" then numTotalRevenue = numTotalRevenue + num1999Total end if strAccountHTML = strAccountHTML & "<TR><TD " & _ "class='calendarinfo'><A Href='' onclick=GetAccount(" & _ "counter & ");window.event.returnValue=false>" & _ oAccount.Subject & "</A></TD></TR>" counter = counter + 1 next numTotalRevenue = CCur(numTotalRevenue) numTotalRevenue = FormatCurrency(numTotalRevenue) TotalRevenue.innerHTML = "<STRONG>" & numTotalRevenue & _ "</STRONG>" strAccountHTML = strAccountHTML & "</TABLE>" Accounts.innerHTML = strAccountHTML YourTasks.innerHTML = "<Strong>" & oTasksCount & "</Strong>" YourAccounts.innerHTML = "<STRONG>" & numFound & "</STRONG>" end sub 'Window_OnLoad --> </SCRIPT> |
Looking at the code, you can see that you need to follow a few critical steps to access the Outlook object model. The first step is to retrieve the Outlook Application object. To do this, you use the Window.External.OutlookApplication syntax. Once you have the Application object, you can retrieve the rest of the Outlook objects. For example, by calling the ActiveExplorer method on the returned Application object, you can retrieve the Explorer object that is hosting the folder home page.
The folder home page is a dynamic environment for the viewing of a folder, as illustrated by the Account Tracking folder home page. In it, the user is presented with a summary of her accounts, account revenue, and tasks. The home page allows you to restrict account tasks to the person currently viewing the folder. (While you could create a similar view in Outlook, you wouldn't be able to specify a filter based on who is viewing the folder.) These account summaries are created by using the Restrict method on the Outlook Items collection for the folder. For the Tasks restriction, the code restricts only those messages in the folder that are tasks, where the current user is the owner and the task status is incomplete. After receiving the restricted set, the code sorts the tasks by their conversation topics, which are the names of the accounts the tasks are for. The code loops through each task to see whether it has a due date. If it does, the code checks to see whether the task is past due. Then the code generates the HTML, which will be placed in the Open Account Tasks list.
For the revenue summary, the code first finds all account items to tally a total. The code restricts the collection to all accounts for which the current user is a team member. Then the code loops through each account and retrieves the revenue, which is stored in the UserProperties collection as custom properties. Since the revenue properties are formula properties, they can contain text that indicates zero revenue from the account. To compensate for this, the code checks whether the value of the property is the string "Zero". The code then builds a string for the restricted list of account names and prints out the account revenue. The string of account names is hyperlinked, as are the tasks, so that a user can quickly go to a specific account or task.
From the code sample, you can see how you can include all the features of the Outlook object model, or any object model for that matter, inside the HTML page you create for your folders.