Skip to Content
0
Former Member
Nov 10, 2011 at 11:52 AM

BPAddresses.Add overwrites AddressName of previously added address

951 Views

Hello,

I'm using the SAP B1 8.81.317 PL:09 DI API to import data to B1.

I noticed that if two addresses are added to an existing BP, THEN the BP is updated as in:

    bp.GetByKey ("C00067")
    Set bpA = bp.Addresses
    bpA.AddressName = "BillTo"
    bpA.Street = "Billto street"
    bpA.AddressType = SAPbobsCOM.BoAddressType.bo_BillTo
    bpA.Add

    bpA.AddressName = "ShipTo"
    bpA.Street = "Shipto street"
    bpA.AddressType = SAPbobsCOM.BoAddressType.bo_ShipTo
    bpA.Add
    bp.Update

...all goes well, but if I add one address, then come back later to the same BP for adding the other address, the AddressName property of the first address is overwritten by the second (the other fields are added correctly).

I though it could be related to this: Add adresses in bussines partner but it is not (trying that solution results in an error for adding an empty address).

This can be easily reproduced by the code below (starting from a BP without any addresses):

    Dim SboGuiApi As New SAPbouiCOM.SboGuiApi
    Dim SBO_App As SAPbouiCOM.Application
    Dim oCompany As New SAPbobsCOM.Company
    SboGuiApi.Connect ("0030002C0030002C00530041005000420044005F00440061007400650076002C0050004C006F006D0056004900490056")
    Set SBO_App = SboGuiApi.GetApplication()
    Set oCompany = SBO_App.Company.GetDICompany()
    Dim bp As SAPbobsCOM.BusinessPartners
    Dim bpA As SAPbobsCOM.BPAddresses
    Set bp = oCompany.GetBusinessObject(oBusinessPartners)
    
    bp.GetByKey ("C00067")
    Set bpA = bp.Addresses
    bpA.AddressName = "BillTo"
    bpA.Street = "Billto street"
    bpA.AddressType = SAPbobsCOM.BoAddressType.bo_BillTo
    bpA.Add
    bp.Update

'(suppose we come back to this BP afterwards)...    

    bp.GetByKey ("C00067")
    Set bpA = bp.Addresses
    bpA.AddressName = "ShipTo"
    bpA.Street = "Shipto street"
    bpA.AddressType = SAPbobsCOM.BoAddressType.bo_ShipTo
    bpA.Add
    bp.Update

The result in the DB is:

SELECT [Address], [AdresType], [Street] FROM [SBO_RFCOM_TESTE].[dbo].[CRD1]
Address	AdresType	Street
ShipTo	B	        Billto street
ShipTo	S	        Shipto street

Note that if this is done in two steps (add BillTo, check the DB, then add ShipTo), the "BillTo" can be seen in the table before the second address is added. Also note that it is not a matter of overwriting/reusing the 1st item of addresses collection, as the AdresType and Street fields do reflect the two different entries.

For importing a batch of data, I can ensure both addresses are added in a single BP update, but for actually adding new addresses to a BP, this would be a problem.

If this is not a bug, what would be the correct way of adding a new address to an existing BP with existing address(es)?

Thanks!

Joao S Veiga