Welcome to Forums Sign in | Join | Help | Forums
in Search


Using the CAPIListener object

Last post 07-20-2006 5:54 AM by David Zeidman. 0 replies.
Page 1 of 1 (1 items)
Sort Posts: Previous Next
  • 07-20-2006 5:54 AM

    • David Zeidman
    • Top 25 Contributor
    • User Since: 2002
    • Posts 326
    • Organization: Zeidman Development
    • Products:  Blackbaud Direct Marketing, Blackbaud Enterprise CRM, The Information Edge, The Raiser's Edge

    Using the CAPIListener object

    In response to William's request for an example of using the CAPIListener I have started this new thread. I have used the CAPIListener for an audit trail. I have an activeX component that tracks changes made on a constituent record. It needs to be informed when a constituent is saved. The ActiveX component contains a factory method that returns the listener. The factory method is shown below: Public Function getAuditEventHandler(sessionContext As IBBSessionContext) As IBBAPIListenerCallback If Not sessionContext Is Nothing Then REUtil.INIT sessionContext Set getAuditEventHandler = New CAuditEventHandler End If End Function I use a factory method so that the user is forced to give the session context. I know that BB insists on makeing you do an INIT for each object but I prefer the factory method design. The CAuditEventHandler object contains code that caputures the type of event: Implements IBBAPIListenerCallback 'This one has to be there as I am implementing the interface above Private Sub IBBAPIListenerCallback_MetaObjectEvent(ByVal lObjectEvent As BBREAPI7.bbObjectEvents, ByVal lObjectType As BBREAPI7.bbMetaObjects, ByVal oMetaObject As BBREAPI7.IBBMetaField, bCancel As Boolean) End Sub 'Here is the main implementation Private Sub IBBAPIListenerCallback_ObjectEvent(ByVal lObjectEvent As BBREAPI7.bbObjectEvents, ByVal lObjectType As BBREAPI7.bbDataObjConstants, ByVal oDataObject As BBREAPI7.IBBDataObject, bCancel As Boolean) On Error GoTo err_Callback 'lObjectEvent allows you to specify which event you want to listen for 'lObjectType allows you to specify which Record type you want to listen for 'both must be specified for the event to be fired. If lObjectEvent = bbOE_ObjectBeforeSave And lObjectType = bbdataConstituent Then 'Do your before save routine here End If End Sub All that is required now is to make use of the listener when we need to use the audit trail. I use this for any customisation that changes constituent data. This saves me from writing audit code each time or even thinking about it. I would use the code as follows: 'This sets up the audit trail to listen to the events. Dim oAuditFac As New CAuditFactory Dim oList As CAPIListener Set oList = New CAPIListener oList.INIT REUtil.getSessionContext, oAuditFac.getAuditEventHandler(REUtil.getSessionContext) 'Now we make a change on our constituent Dim oConstit as New CRecord oConstit.INIT REUtil.getSessionContext oConstit.Fields(RECORDS_fld_FIRST_NAME) = "David" oConstit.Save 'The audit trail will capture this event oConstit.Closedown Set oConstit = Nothing Hope this helps anyone who is interested in using this. It can be very useful especially when you have multiple customisations that require each other's functionality. If you have any questions then please do not hesitate to contact me. David Zeidman Development http://www.zeidman.info  --- Edited at 7/20/2006 5:58:58 AM by David Zeidman
    David Zeidman
    Zeidman Development
    http://www.zeidman.info

    Check out my RE API blog
    http://www.re-decoded.com
Page 1 of 1 (1 items)