Share via


Registering a Workflow Event Sink in a Folder

Registering a Workflow Event Sink in a Folder

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

The workflow event sink handles OnSyncSave, OnSyncDelete, and OnTimer events in any Exchange store folder where it is registered. When a user saves or deletes an item in a folder, an event occurs. When the event occurs in a folder, the Exchange store process looks for an event registration item in the folder. The registration item tells the Exchange store which process handles the event. You need to tell the Exchange store that you want the workflow event sink process to handle OnSyncSave, OnSyncDelete, and OnTimer events in your folder. This is referred to as registering the workflow event sink in a folder.

The following rules govern the registration of an event sink:

  • The event type must be one of the three supported types: OnSyncSave, OnSyncDelete, or OnTimer.
  • The user who registers the workflow must be a member of the Can Register Workflow role. For more information about registering workflow authors, see Registering Workflow Authors.
  • The Workflow System Account must have at least read privileges in the folder. Events that make changes to the folder contents require that the Workflow System Account have both read and write privileges in the folder.
  • You cannot set the MatchScope Field of the registration to ANY.
  • You cannot register the event sink for a synchronous event with the MatchScope Field set to DEEP if it is already registered in a subfolder of the same folder.
  • You cannot register the event sink in a child folder when it is already registered in the parent folder with the MatchScope Field set to DEEP.
  • The OnTimer event occurs for every workflow folder on the server.
  • For OnTimer events, you can only set the MatchScope Field to DEEP on public folder trees that you create. The MatchScope Field cannot be set to DEEP for OnTimer events in the default public folder tree.

Note   The store event registrations set the criteria field with an SQL WHERE clause to prevent other registrations, ProcessDefinitions, and CommonScripts from raising events in the folder.

The following code registers a workflow application folder for the OnTimer system event, the OnSyncSave store event, and the OnSyncDelete store event. In this example, the OnTimer event causes the workflow event sink to run every 15 minutes.

Visual Basic

  Dim EventRuleItem As String
  Dim sEvtRegURL As String
  Dim ProcessDefinitionURL As String

'''''''''''''''''''''Register OnTimer Event

  EventRuleItem = "OnTimerRule"

  sEvtRegURL = sFolderURL & EventRuleItem

  ' The event registration item (sEvtRegURL) must be saved
  ' in the folder for which you want to register
  ' the workflow sink.

  Dim Rec As ADODB.Record
  Set Rec = New ADODB.Record

  Rec.Open sEvtRegURL, , adModeReadWrite, _
                       adCreateNonCollection Or adCreateOverwrite, _
                       adDelayFetchFields
  If Err.Number <> 0 Then
     Debug.Print "Failed to open event registration record." & Err.Description
  End If

  Dim Flds As ADODB.Fields
  With Rec
    Set Flds = .Fields
    Flds("DAV:contentclass") = "urn:content-class:storeeventreg"
    Flds("https://schemas.microsoft.com/exchange/events/EventMethod") = "OnTimer"
    Flds("https://schemas.microsoft.com/exchange/events/SinkClass") = "CdoWfEvt.EventSink.1"
    Flds("https://schemas.microsoft.com/exchange/events/TimerStartTime") = #5/1/1999#
    Flds("https://schemas.microsoft.com/exchange/events/TimerInterval") = 720
    Flds("https://schemas.microsoft.com/exchange/events/TimerExpiryTime") = #8/4/2000#
    Flds.Update
    .Close
  End With

'''''''''''''''''''''Register OnSyncSave and OnSyncDelete Events

  EventRuleItem = "OnSyncSave_OnSyncDelete_Rule"

  sEvtRegURL = sFolderURL & EventRuleItem

  ProcessDefinitionURL = sProcDefURL

  Rec.Open sEvtRegURL, , adModeReadWrite, _
                       adCreateNonCollection Or adCreateOverwrite, _
                       adDelayFetchFields
  If Err.Number <> 0 Then
     Debug.Print "Failed to open event registration record." & Err.Description
  End If

  With Rec
    Set Flds = .Fields
    Flds("DAV:contentclass") = "urn:content-class:storeeventreg"
    Flds("https://schemas.microsoft.com/exchange/events/EventMethod") = "OnSyncSave;OnSyncDelete"
    Flds("https://schemas.microsoft.com/exchange/events/SinkClass") = "CdoWfEvt.EventSink.1"
    Flds("https://schemas.microsoft.com/exchange/events/Criteria") = "WHERE $DAV:ishidden$ AND $DAV:iscollection$ = FALSE"
    Flds("https://schemas.microsoft.com/cdo/workflow/defaultprocdefinition") = ProcessDefinitionURL
    Flds("https://schemas.microsoft.com/cdo/workflow/adhocflows") = 0
    Flds("https://schemas.microsoft.com/cdo/workflow/enabledebug") = True
    Flds("https://schemas.microsoft.com/cdo/workflow/disablesuccessentries") = False
    Flds.Update
    .Close
  End With

Send us your feedback about the Microsoft Exchange Server 2003 SDK.

Build: June 2007 (2007.618.1)

© 2003-2006 Microsoft Corporation. All rights reserved. Terms of use.