Skip to Content
0
Former Member
Jun 20, 2014 at 01:11 PM

Add or update contact employees for BP using SDK

1194 Views

Hi all, I have a function to add or update BP's contact employees. My function tests if contact exists, so update, if not add new one. BUT I noticed the following:
whether BP has 1 contact or not property count always gives 1 (sboContacts.Count=1).
All updates and add happen in OCRD table not OCPR table. So 2nd contact never been added.
here is my function:
private bool UpdateContactName(string bpCardCode, string ctnPrevName, string CtnNewName)

{

bool bRetVal = false;

string sErrMsg; int lErrCode;

//Check connection before updating

if (clsBP.Connect_SAP() == 0)

{

//create the BP object

SAPbobsCOM.BusinessPartners BP = clsBP.vCmp.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oBusinessPartners);

try

{

if (BP.GetByKey(bpCardCode))

{

SAPbobsCOM.ContactEmployees sboContacts = (SAPbobsCOM.ContactEmployees)BP.ContactEmployees;

//check first for one contact (always gives 1 whether have contact or not) check for no contact to add or update

if (sboContacts.Count 1)

{

for (int i = 0; i < sboContacts.Count; i++)

{

sboContacts.SetCurrentLine(i);

if (sboContacts.Name == ctnPrevName)

{

bRetVal = true;

sboContacts.Name = CtnNewName;

}

}

}

if (bRetVal)

{

if (BP.Update() != 0)

{

bRetVal = false;

clsBP.vCmp.GetLastError(out lErrCode, out sErrMsg);

}

}

}

}

catch (Exception ex)

{

bRetVal = false;

}

}

clsBP.vCmp.Disconnect();

return bRetVal;

}

I want to update both Default contact Person in OCRD table and update or add in OCPR table too.

I have SAP B1 9.02

Thanks a lot, Samira