Start a new topic

Finding what fields have changed

I'm helping a client with extensive API code diagnose an issue. She has code to only populate virtual fields if that row was supposed to create a gift. Some rows that should not have created a gift were doing so, even though the code tester did not show any values in those virtual fields. I thought I'd share something that might be useful in helping track down this or other issues: the IBBMetaObject and IBBDataObject. Using these interfaces we can cycle through all the fields in a record to see which ones are dirty, then output a list of them. This is code I made in VBA, but it could be converted for use in the IOM API (perhaps on the gift before save) to see which fields have changed and what the value is, as a clue to what value in the row is causing the gift to be created. If anyone converts it for use in IOM, please post the code. Thanks!

 

Public Sub TestFieldIsDirtyOnNewRec()

    Dim o As CGift

    Set o = New CGift

    o.Init REApplication.SessionContext

    Dim oDO As IBBDataObject

    Set oDO = o

    Dim oMeta As IBBMetaField

    Set oMeta = o

    

    Dim i As Integer

    

    For i = 1 To oMeta.Count

        If oDO.FieldIsDirty(i) Then

            Debug.Print oMeta.Name(i) & " = " & o.Fields(i)

        End If

    Next

    o.Closedown

End Sub

 

By the way, for a brand new, untouched/unsaved gift record, the following fields were already dirty:

 

Currency Country = United States

Date = 7/14/2015

GL post date = 7/14/2015

Gift status date = 7/14/2015

Reversal NL post date = 7/14/2015


Very cool Jeff

My favorite "trick" for debugging RE objects is QuickView.  It pops up a nice window with all of the meta data about the object.

ex. to see all of the metadata about the preferred address on a record

CType(oRec.PreferredAddress, Blackbaud.PIA.RE7.BBREAPI.IBBDataObject).QuickView


I did write a little function to return a string with all of the fields and if they are dirty or not in case anyone is interested.

You call it like:

FieldDump(Of Blackbaud.PIA.RE7.BBREAPI.ERECORDSFields)(oRec)


The code for the function:

    Public Shared Function FieldDump(Of T)(oObj As Blackbaud.PIA.RE7.BBREAPI.IBBDataObject) As String

 

        Dim sOutput As String

        sOutput = oObj.GetType().ToString() & " : " & iif(oObj.Dirty = True, "DIRTY", "clean") & VbCrLf & vbCrLf

        For Each iEnumVal As Integer In System.Enum.GetValues(GetType(T))

            Try

                sOutput &= IIf(oObj.FieldIsDirty(iEnumVal) = True, "***", "")

                sOutput &= System.Enum.GetName(GetType(T), iEnumVal) & " -> "

                sOutput &= oObj.Fields(iEnumVal)

            Catch ex As Exception

                ' Do nothing, this happens if you are checking a field for a module that you don't have

            Finally

                sOutput &= vbCrLf

            End Try

        Next

 

        Return sOutput

    End Function

Wayne, awesome stuff! Also, a developer here also suggested using ShowRow to see all the fields and values that are being imported for the current row. Just call it like this from the IOM API:

Import.ShowRow()
Login or Signup to post a comment