I am trying to work out how to add a new package to an appeal if the imported one does not exist.
In the virtual column to set the package I am checking to see if it exists, and if it doesn't, creating it. It get the error: Line 1: Invalid Package: Package Id [Object: 'CGiftSplit', PK: '-1', Import ID: '', Field: 'Package Id', Value: 'Email'] -->BBREAPI.CGiftClass.Save()
I think it has something to do with the timing of when the record is saved and when the package is checked for validity. What order should I be running this in to create the new package before the package is checked?
Assuming that sReturn contains the new package name here is my code (the MsgBoxes all go off correctly so I assume this works...):
Dim oAppeal As New CAppealClass Dim oPackage As CPackage Dim bFound As Boolean = False
oAppeal.Init(Import.SessionContext) oAppeal.LoadByField(EAPPEALFields.Appeal_fld_Appeal_ID, Import.Fields.GetByName("Appeal").Value) MsgBox("Loaded: " & oAppeal.Fields(EAPPEALFields.Appeal_fld_Appeal_ID)) For Each oPackage In oAppeal.Packages If oPackage.Fields(EPackageFields.Package_fld_ID) = sReturn bFound = True Exit For End If Next If Not bFound Then MsgBox("Not Found") Dim oNewPack As CPackage oNewPack = oAppeal.Packages.Add oNewPack.Fields(EPackageFields.Package_fld_ID) = sReturn oNewPack.Fields(EPackageFields.Package_fld_DESCRIPTION) = sReturn & " - Auto Created" MsgBox("Added: " & oNewPack.Fields(EPackageFields.Package_fld_ID) & " Pack: " & oNewPack.Fields(EPackageFields.Package_fld_DESCRIPTION)) End If
Looks like you are simply missing the call to save on your package. oNewPack.Save()
N
Nic Bourne
said
over 9 years ago
Wayne,
Additionally, you are attempting to set the ID of the package. This is actually the primary key ID in the database. What you actually want to set is the Blackbaud.PIA.RE7.BBREAPI.EPackageFields.Package_fld_Package_ID
W
Wayne Pozzar
said
over 9 years ago
W
Wayne Pozzar
said
over 9 years ago
Woop, it worked!
I actually did oAppeal.Save() just FYI to anyone looking at this in the future.
Wayne Pozzar
Hello again,
I am trying to work out how to add a new package to an appeal if the imported one does not exist.
In the virtual column to set the package I am checking to see if it exists, and if it doesn't, creating it. It get the error: Line 1: Invalid Package: Package Id [Object: 'CGiftSplit', PK: '-1', Import ID: '', Field: 'Package Id', Value: 'Email'] -->BBREAPI.CGiftClass.Save()
I think it has something to do with the timing of when the record is saved and when the package is checked for validity. What order should I be running this in to create the new package before the package is checked?
Assuming that sReturn contains the new package name here is my code (the MsgBoxes all go off correctly so I assume this works...):
Dim oAppeal As New CAppealClass
Dim oPackage As CPackage
Dim bFound As Boolean = False
oAppeal.Init(Import.SessionContext)
oAppeal.LoadByField(EAPPEALFields.Appeal_fld_Appeal_ID, Import.Fields.GetByName("Appeal").Value)
MsgBox("Loaded: " & oAppeal.Fields(EAPPEALFields.Appeal_fld_Appeal_ID))
For Each oPackage In oAppeal.Packages
If oPackage.Fields(EPackageFields.Package_fld_ID) = sReturn
bFound = True
Exit For
End If
Next
If Not bFound Then
MsgBox("Not Found")
Dim oNewPack As CPackage
oNewPack = oAppeal.Packages.Add
oNewPack.Fields(EPackageFields.Package_fld_ID) = sReturn
oNewPack.Fields(EPackageFields.Package_fld_DESCRIPTION) = sReturn & " - Auto Created"
MsgBox("Added: " & oNewPack.Fields(EPackageFields.Package_fld_ID) & " Pack: " & oNewPack.Fields(EPackageFields.Package_fld_DESCRIPTION))
End If