SAP Business one Business Partners: Adding/Updating

4.7
(6)

How to add a Business Partner:

// Create an instance of the BP object
SAPbobsCOM.BusinessPartners sboBP = (SAPbobsCOM.BusinessPartners)_sboCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oBusinessPartners);
 
// Set the basic properties
sboBP.CardCode = "S00001";
sboBP.CardName = "New Supplier 1";
sboBP.CardType = SAPbobsCOM.BoCardTypes.cSupplier;
// Set optional properties
sboBP.CreditLimit = 100000;
sboBP.Currency = "USD";
 
// Add the BP
int iRetVal = sboBP.Add();
if(iRetVal != 0)
{
    // Add failed so report error to user
    _sboApp.SetStatusBarMessage("Error creating BP: " + _sboCompany.GetLastErrorDescription(), SAPbouiCOM.BoMessageTime.bmt_Medium, true); 
}

How to add an address to an existing BP:

// Create an instance of the BP object
SAPbobsCOM.BusinessPartners sboBP = (SAPbobsCOM.BusinessPartners)_sboCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oBusinessPartners);
 
// Use the GetByKey method to retrieve the existing BP
if (sboBP.GetByKey("S00001"))
{
    SAPbobsCOM.BPAddresses sboAddresses = (SAPbobsCOM.BPAddresses)sboBP.Addresses;
    // Check to see if addresses already exist
    if (sboAddresses.Count > 1)
    {
        sboAddresses.Add();
    }
    else
    {
        // First address always exists, but may be blank
        sboAddresses.SetCurrentLine(0); 
        if (sboAddresses.AddressName != "") sboAddresses.Add();
    }
    sboAddresses.SetCurrentLine(sboAddresses.Count - 1);
    // Set the properties for the new address
    sboAddresses.AddressName = "Billing2";
    sboAddresses.AddressType = SAPbobsCOM.BoAddressType.bo_BillTo;
    sboAddresses.Street = "789 Virtual Street";
    sboAddresses.ZipCode = "1234";
 
    // Update the BP
    int iRetVal = sboBP.Update();
    if (iRetVal != 0)
    {
        // Update failed so report error to user
        _sboApp.SetStatusBarMessage("Error updating BP: " + _sboCompany.GetLastErrorDescription(), SAPbouiCOM.BoMessageTime.bmt_Medium, true);
    }
}
else
{
    // BP wasn't found so report error
    _sboApp.SetStatusBarMessage("Unable to find S00001 in the database", SAPbouiCOM.BoMessageTime.bmt_Medium, true);
}

How to update an existing address on a BP:

// Create an instance of the BP object
SAPbobsCOM.BusinessPartners sboBP = (SAPbobsCOM.BusinessPartners)_sboCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oBusinessPartners);
 
// Use the GetByKey method to retrieve the existing BP
if (sboBP.GetByKey("S00001"))
{
    SAPbobsCOM.BPAddresses sboAddresses = (SAPbobsCOM.BPAddresses)sboBP.Addresses;
    // Loop through the addresses to get to the correct address
    for (int i = 0; i <= sboAddresses.Count - 1; i++)
    {
        sboAddresses.SetCurrentLine(i);
        if (sboAddresses.AddressName == "Billing" && sboAddresses.AddressType == SAPbobsCOM.BoAddressType.bo_BillTo)
        {
            // This is the address I want to update so change the properties
            sboAddresses.Street = "765 Virtual Road";
            break;
        }
    }
    // Update the BP
    int iRetVal = sboBP.Update();
    if (iRetVal != 0)
    {
        // Update failed so report error to user
        _sboApp.SetStatusBarMessage("Error updating BP: " + _sboCompany.GetLastErrorDescription(), SAPbouiCOM.BoMessageTime.bmt_Medium, true);
    }
}
else
{
    // BP wasn't found so report error
    _sboApp.SetStatusBarMessage("Unable to find S00001 in the database", SAPbouiCOM.BoMessageTime.bmt_Medium, true);
}

 

How useful was this post?

Click on a star to rate it!

Average rating 4.7 / 5. Vote count: 6

No votes so far! Be the first to rate this post.

As you found this post useful...

Share this post on social media!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?