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
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
If Not bFound Then
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))