Programming Microsoft Outlook and Microsoft Exchange, Second Edition (DV-MPS Programming)

The Exchange Server Routing Object library is provided by Microsoft so that you can create process instances, create and edit routing maps, and track the progress of your process instances. The Routing Object library, which is provided in the file exrtobj.dll, is a hierarchical object library like CDO. In fact, the Routing Object library was built with the expressed intention to be used with the CDO object library. Figure 13-10 shows the objects contained in the Routing Object library.

With this object library, you can create some interesting applications. To help demonstrate how useful and powerful this object library is, we will take a look at an update to the Agent Install program from Chapter 12. This program has been updated to allow you to edit routing maps and track the state or process instances in a folder. Before looking at the updated Agent Install program, however, you first must take a look at the objects in the library so that you have a firm understanding of their functionality. I'll provide the most important properties and methods you will likely use in your applications. Refer to the Agents.hlp file on the Exchange Server 5.5 Service Pack 1 CD for the full listing of properties and methods for the objects. Also, check out the Exchserv.chm file on the companion CD and the Microsoft TechNet site http://www.microsoft.com/technet/download/exchange/.

Figure 13-10 The objects in the Routing Object library.

RouteDetails Object

The RouteDetails object is a top-level object in the library. You should never explicitly create a RouteDetails object; it is passed to the VBScript subroutines that you write for the folder in the same way that the EventDetails object is passed to your VBScript event scripts. Since the routing objects are built on the Event Scripting technology, both the RouteDetails object and the EventDetails object are passed to your VBScript functions.

The RouteDetails object contains a number of properties that you will want to use in your VBScript functions, including the following:

As you can see, the RouteDetails properties return full CDO objects, unlike the EventDetails object, which returns only EntryID properties for the message and the folder. Using the RouteDetails properties avoids the need to bind to a message or a folder in the Exchange Server store each time a script is run, so your scripts will achieve greater performance.

That said, there is one important object that is not available through the RouteDetails object and available only through the EventDetails object—the CDO Session object, which is the pre-logged-on CDO Session that the script is running under. To retrieve all the objects you want to use in your scripts, you must use both the RouteDetails and the EventDetails objects together. The following code shows how to initialize your VBScript objects with all the RouteDetails properties:

Set g_oSession = EventDetails.session Set g_oMsgIn = RouteDetails.Msg Set g_oFolder = RouteDetails.Folder Set g_oProcInstance = RouteDetails.ProcInstance

ProcInstance Object

The ProcInstance object is a top-level object that can be created independently of any other objects in the Routing Object library, or that can be obtained by using the ProcInstance property of the RouteDetails object. The ProcInstance object represents a process instance that is a work item and some additional properties for state and map information. When tracking processes in your routing object applications, you will use the ProcInstance object extensively. Some of the important properties and methods for this object include the following:

The following code snippet, written in Visual Basic, shows you how to use some of these properties and methods. It assumes you already have a valid CDO Message object, named oMessage, that corresponds to the process instance you are interested in.

Set oRTProcInstance = CreateObject("exrt.ProcInstance") oRTProcInstance.Message = oMessage oRTProcInstance.Open msgbox "The current executing row is " & oProcInstance.CurrentRow if oProcInstance.Terminated = 0 then msgbox "The process is not terminated." Else Msgbox "The process is terminated." End if Msgbox "The RUI for this process instance is " & oProcInstance.RUI 'This shows how to retrieve the properties that require object 'variables set oMap = oProcInstance.Map set oLog = oProcInstance.Log

Map Object

The Map object represents the routing map that is evaluated and used by the engine when executing process instances. There must be a default map in every routing folder. This map is copied onto incoming messages when the messages do not already contain maps.

The Map object is a top-level object that can be created independently of other objects in the library, so you can create maps and edit maps without creating a ProcInstance object. The following are the major properties and methods for this object:

The following code snippet shows you how to use some of these methods and properties in your own programs. It assumes you have a valid CDO Message object, named oMessage.

Set oRTMap = CreateObject("exrt.map") oRTMap.Message = oMessage oRTMap.OpenMap 1 'Read/Write msgbox "Activity Count is " & oRTMap.ActivityCount 'Retrieve a row by using the GetRow method. 'First, create the Row object. set oRTRow = CreateObject("exrt.row") oRTMap.GetRow 1, oRTRow 'Get the first row 'Change the Flags property on the row oRTRow.Flags = 2 'Need to save the map now oRTMap.SaveMap 'Need to change a property on the message to have the 'Update method work correctly oMessage.Subject = oMessage.Subject & " " 'Need to call the CDO Message Update method to persist changes on 'the message oMessage.Update

Row Object

The Row object represents a single row in your map. You can create a Row object independent of the other objects in the library. After creating a Row object, you should set its properties and add it to your map. If you are retrieving a row from an existing map, to store the row, you must pass in a variable that corresponds to your Row object. The following are the most important properties and methods for this object:

The following code snippet shows you how to use the Row object. Note that you must convert to the correct format any arguments you pass to the methods and properties. If a method is expecting a Long value, pass a Long value. This example assumes you already have a valid Map object set to oRTMap.

'This example creates a row, fills it in, and adds it to a map Set oRTRow = CreateObject("exrt.row") Dim arrParameters(2) 'Two parameters arrParameters(1) = "Test" arrParameters(2) = "Test2" 'If the parameters are numbers, use CLng. 'See the AgentInstall update later in this chapter for more 'information. oRTRow.SetArgs 2, arrParameters 'Use CLng if not already a long oRTRow.ActivityID = 100 'Use CStr if not a string oRTRow.Action = "My Custom Action" 'Use CLng if not already a long oRTRow.Flags = 2 'Inser the Row into the Map oRTMap.InsertActivity _1, oRTRow oRTMap.SaveMap 'Then update the message, as shown in the previous code snippet

Log Object

The Log object allows you to log activities that execute in your map. This object stores its log differently from the way logs are stored in the Event Agent log. The only way you can retrieve the Log object is by using the Log property on the ProcInstance object. You cannot create a separate instance of this object. The following are the methods of the Log object:

The following code snippet shows you how to insert an item into the log. The code assumes that you have a valid ProcInstance object named oRTProcInstance.

Set oRTLog = oRTProcInstance.Log oRTLog.AddLogEntry "MyApp", "MyNameID", CLng(10/1/1998), "MyDescrip" 'Save the log oRTLog.SaveLog

Participant Object

The Participant object provides a way to refer to and manipulate addresses (which can be actual e-mail addresses or roles) in your routes and resolve roles to actual addresses. For example, you would use the Participant object to find out who the manager or expense approver for a certain user is by passing in the address of that user. This object would then return to you the address of the person who performs the role you specified. The three important methods of this object include the following:

The following sample code shows you how to use this object in the VBScript subroutines for your routes. It assumes that you already have a valid ProcInstance object named oRTProcInstance.

Set oParticipant = oRTProcInstance.Participant 'This can be also Manager or another custom RoleName you make oParticipant.RoleName = "Expense Approver" 'Or you could pass the address oParticipant.MemberName = "Thomas Rizzo" 'Get the address of the expense approver ExApproverAddress = oParticipant.ResolveRole

VoteTable Object

The VoteTable object allows server-based applications to create Outlook voting-button messages. The Exchange Server Routing Objects do not need to rely on the Outlook object model to do this; they include the functionality to create them. Being able to create voting buttons makes it easy for your Outlook users to select custom responses, such as Approve or Reject, for your routed items. The VoteTable object can also be used to consolidate voting button response messages in the original process instance. This consolidation saves time since you do not have to write this code yourself to consolidate the responses. Furthermore, this object updates the Tracking tab in Outlook without needing code from you.

The VoteTable object can be created as a separate object or retrieved by using the VoteTable property of a ProcInstance object. The VoteTable object is used in conjunction with the RecipientEntry object, which is discussed later in this chapter. The following list describes the properties and methods for the VoteTable object:

The following code example shows you how to create a voting button message. It assumes you already have a valid CDO Message object called oMessage.

Set oRTVoteTable = CreateObject("exrt.VoteTable") 'You could also use the VoteTable property on the ProcInstance 'object to get a VoteTable object. 'Create the buttons. oRTVoteTable.AddButtons oMessage, "approve,reject,undecided" 'Send the message oMessage.Send

The next code snippet shows you how to consolidate voting button responses received in a folder. This example assumes you have a valid CDO Message object in oMessage.

'Use the ProcInstance VoteTable set oRTVoteTable = oRTProcInstance.VoteTable 'oMessage is the voting response message, True means to autoadd oRTVoteTable.ConsolidateResponse oMessage, True oRTVoteTable.Save

RecipientEntry Object

The RecipientEntry object is always used to track the response of a recipient in the route and the date that recipient responded. The RecipientEntry object is typically used in conjunction with the VoteTable object. The following properties are available for the RecipientEntry object:

The following code shows you how to create and fill in a RecipientEntry object. The code will also show you how to add this RecipientEntry object to the VoteTable object. This code assumes you have a valid oRTProcInstance object.

Set oRTVoteTable = oRTProcInstance.VoteTable Set oRecipientEntry = CreateObject("exrt.RecipientEntry") oRecipientEntry.Recipient = "My Name" oRecipientEntry.Date = "11/1/1998 10:00 AM" oRecipientEntry.Status = "Approve" oRTVoteTable.ConsolidateResponse oRecipientEntry, False oRTVoteTable.Save

WorkItem Object

The WorkItem object can be retrieved only as a property of the RouteDetails object. The WorkItem object can represent a new item in the folder before a related process instance for the item is found, or a new item in the folder until that item is turned into a process instance. Most of the time, your applications will not call the methods and properties of the WorkItem object directly. Rather, the routing engine will call the methods. The only exceptions to this are the following:

To illustrate how these methods and properties work, the following sample code sets a WorkItem object to a CDO Message object. It then embeds another message in the existing CDO Message. The code also consolidates all attachments from another message into the WorkItem CDO Message object. This sample assumes you have a RouteDetails object.

'Get the WorkItem object Set oWorkItem = RouteDetails.WorkItem 'Set the Item property to the current process instance oWorkItem.Item = oProcInstanceMessage 'Embed another message into the oProcInstanceMessage oWorkItem.EmbedMsg oAnotherMessage 'Consolidate all the attachments from another message into 'the WorkItem message. 'Create an array of propIDs. PropArray = Array(&HE13000D) 'For msg attachments 'Append items by selecting True oWorkItem.ItemConsolidate PropArray, omsgSource, True

Категории