This example demonstrates how to find or create a NotificationIndividual object for a given e-mail address.
This code returns a NotificationIndividual object for a given SMTP e-mail address. If an existing NotificationIndividual already uses the specified e-mail address, that NotificationIndividual is returned. Otherwise a new NotificationIndividual is created and returned.
The method requires an existing client connection. See Creating a Client Session for an example of creating a client connection.
Usage:
dim aRecipient as NotificationIndividual aRecipient=NotificationRecipientGetter.GetRecipient(connection,"joe user","[email protected]")
Public Class NotificationRecipientGetter 'Gets a NotificationIndividual object for the specified e-mail address. 'GetRecipient first checks to see if there is an existing NotificationIndividual 'that uses the specified e-mail address. If so, that NotificationIndividual is 'returned. 'Otherwise, GetRecipient creates a new NotificationIndividual and NotificationAddress 'to represent the name and e-mail address. Public Shared Function GetRecipient(ByVal connection As Scheduler, ByVal name As String, ByVal emailAddress As String) As NotificationIndividual Dim recipients As ADTObjects Dim address As NotificationAddress Dim recipient As NotificationIndividual Dim filter As New NotificationRecipientFilter(emailAddress) Dim recordCount As Int32 'check to see if there's already a NotificationIndividual that 'uses this e-mail address. At this point we only look at the 'e-mail address, and ignore the name. recipients = connection.GetObjectsWhere(filter, 1, True, recordCount) If recipients.Count > 0 Then 'There is already a Notification Recipient for this Return CType(recipients(0), NotificationIndividual) End If 'no existing recipient found; create a new one recipient = CType(connection.CreateObject(ClassIDEnum.CID_NotificationIndividual), NotificationIndividual) recipient.Name = name address = CType(connection.CreateObject(ClassIDEnum.CID_NotificationAddress), NotificationAddress) address.AddressType = NotificationAddressTypeEnum.natSMTP address.RecipientAddress = emailAddress recipient.Addresses.Add(address) 'We don't need to save the Recipient here, because it will get saved by whatever object it 'gets associated with. Return recipient End Function 'Filter used with IScheduler.GetObjectsWhere to get the notification 'recipient(s) associated with a given e-mail address. Private Class NotificationRecipientFilter Implements IObjectRequestFilter Public EMailAddress As String = "" Public Sub New(Optional ByVal address As String = "") EMailAddress = address End Sub Public Function GetOrderClause() As String Implements ArcanaDevelopment.adTempus.Client.IObjectRequestFilter.GetOrderClause Return "" End Function Public Function GetSelectClause() As String Implements ArcanaDevelopment.adTempus.Client.IObjectRequestFilter.GetSelectClause Return "*" End Function Public Function GetTableName() As String Implements ArcanaDevelopment.adTempus.Client.IObjectRequestFilter.GetTableName Return "notificationIndividual" End Function Public Function GetWhereClause() As String Implements ArcanaDevelopment.adTempus.Client.IObjectRequestFilter.GetWhereClause Return "oid in (select owner from notificationaddress where addressType=1 and address='" & EMailAddress & "')" End Function End Class End Class
adTempus API Reference version 3.0.0.0, revised 10/30/2008
|