Start a new topic
Answered

Retrieving Last Gift

Hi,

I'm trying to use the answer given here:

https://omaticsoftware.freshdesk.com/support/discussions/topics/28000006750

...to pull through the Last Gift details for a record. (I want to change the coding on a donation on import if the last gift was within two years.)

However, it doesn't seem to be working for me. 

Can anyone tell me why the below wouldn't assign the correct Last Gift Date to reLastGiftDate?


========================


 Public Overrides Sub AfterConstituentOpen(ByVal oRec As Blackbaud.PIA.RE7.BBREAPI.CRecord, ByVal Cancel As ImportOM.API.iCancel)

 MyBase.AfterConstituentOpen(oRec, Cancel)

  ' Get the RE last gift date and check it against the incoming gift date

  ' If the RE last gift date less than 2 years ago, then change coding

  ' Get the Last Gift from the current RE Record 


  Dim oLastGift As New blackbaud.PIA.RE7.BBREAPI.CGiftClass

  With oLastGift

   .Init(Import.SessionContext)

   ' **NOTE** this might fail if there is not a last gift so you should probably put in some error checking

   .Load(oRec.Fields(Blackbaud.PIA.RE7.BBREAPI.ERECORDSFields.RECORDS_fld_LAST_GIFT))

  End With

  ' Get the Date of the Last Gift from the current record

  Dim reLastGiftDate As Date = oLastGift.Fields(Blackbaud.PIA.RE7.BBREAPI.EGiftFields.GIFT_fld_Date)


Best Answer

I couldn't get it to work either.  It seems as the .RECORDS_fld_LAST_GIFT doesn't pull the correct gift.  Even Blackbaud's KB doesn't reference first gift or last gift, they just have you sort.  https://kb.blackbaud.com/articles/Article/43238  So I just did it this way instead


Public Overrides Sub AfterConstituentOpen(oRec As CRecord, Cancel As ImportOM.API.iCancel)
        MyBase.AfterConstituentOpen(oRec, Cancel)


        Dim lastGiftDate as New Date
        If oRec.Gifts.Count > 0 Then

            With oRec.Gifts
                .SortField = EGiftFields.GIFT_fld_Date
                .SortOrder = bbSortOrders.Descending
                lastGiftDate  = .Item(1).Fields(EGiftFields.GIFT_fld_Date)

            End With
        End If

    End Sub


Thanks,


John


Answer

I couldn't get it to work either.  It seems as the .RECORDS_fld_LAST_GIFT doesn't pull the correct gift.  Even Blackbaud's KB doesn't reference first gift or last gift, they just have you sort.  https://kb.blackbaud.com/articles/Article/43238  So I just did it this way instead


Public Overrides Sub AfterConstituentOpen(oRec As CRecord, Cancel As ImportOM.API.iCancel)
        MyBase.AfterConstituentOpen(oRec, Cancel)


        Dim lastGiftDate as New Date
        If oRec.Gifts.Count > 0 Then

            With oRec.Gifts
                .SortField = EGiftFields.GIFT_fld_Date
                .SortOrder = bbSortOrders.Descending
                lastGiftDate  = .Item(1).Fields(EGiftFields.GIFT_fld_Date)

            End With
        End If

    End Sub


Thanks,


John

Amazing. John, thanks so much for this. My import is now working!


Thanks,

Jack

Login or Signup to post a comment