I need to inactivate thousands of abandoned Leads. I'm doing it by loading up each one, setting Valid = NO, and saving it back to the database. Here is my code:
var ocrd = Company.GetBusinessObject( SAPbobsCOM.BoObjectTypes.oBusinessPartners ) as SAPbobsCOM.BusinessPartners;
foreach ( var cardCode in abandonedLeadList ) {
if ( ocrd.GetByKey( cardCode ) ) {
ocrd.Valid = SAPbobsCOM.BoYesNoEnum.tNO;
if ( ocrd.Update() != 0 ) {
// Code here to keep a list of the ones we could not write, along with error codes and messages
}
}
}
The intent of this change is to inactivate the record by setting its validFor
flag to 'N'.
I have stepped through this code when debugging. The call to ocrd.Update()
returns 0, indicating success, and in the database, the record's UpdateDate and UpdateTS indicate a save happens -- but the validFor
flag remains 'Y' after the update, and the Lead remains active.
What am I missing? What is the proper way to inactivate a Business Partner programmatically?
My SAP version is Business One 9.3 (9.30.180) PL:08 (64-bit)
To make a Business Partner inactive use the Frozen
Property via the
DI-API along with the Valid
Property:
ocrd.Valid = SAPbobsCOM.BoYesNoEnum.tNO
ocrd.Frozen = SAPbobsCOM.BoYesNoEnum.tYES