Skip to Content
0
Former Member
Jan 26, 2009 at 03:40 PM

Add New Activity using DI API

386 Views

Dear Sir,

I am trying to develop an add on that create an activity using DI API;

I am using the following code:

*********************************************************************************

Private Sub cmdTest_Click()

On Error GoTo ErrorHandler

Dim vCompany As SAPbobsCOM.Company

'Création du2019un objet Company

Set vCompany = New SAPbobsCOM.Company

'Configuration des paramétres de connexion

vCompany.CompanyDB = "SBODemo_US"

vCompany.Password = "manager"

vCompany.UserName = "manager"

vCompany.Server = "(local)"

'Connexion au serveur de base de données

If (0 <> vCompany.Connect()) Then

MsgBox "Failed to connect"

Exit Sub

End If

Dim nErr As Long

Dim errMsg As String

'Ajout du2019une activité avec le partenaire HU1001, le Dec 15, 2002

'Si lu2019activité existe déjà, alors on la raffraichira, sinon on la crée

Dim bFound As Boolean

bFound = False

Dim iNum As Long

iNum = 1

Dim vContact As SAPbobsCOM.Contacts

Set vContact = vCompany.GetBusinessObject(oContacts)

While ((vContact.GetByKey(iNum) = True) And (bFound = False))

If (vContact.CardCode = "HU1001") Then

If (vContact.Closed = tNO) Then

bFound = True

End If

End If

iNum = iNum + 1

Wend

vContact.CardCode = "HU1001"

vContact.Closed = tNO

vContact.ContactDate = CDate("15/12/2002")

vContact.Notes = "Discuss next year's financial plan"

If (bFound = False) Then

'Aucune activité similaire trouvée, donc on en crée une

vContact.DocType = oContacts

If (vContact.Add() <> 0) Then

MsgBox "Echec"

Else

MsgBox ("Activité ajoutée avec succés")

vContact.SaveXml ("C: empContact" + vContact.DocEntry + ".xml")

End If

Else

If (0 <> vContact.Update()) Then

MsgBox ("Echec de la mise à jour de lu2019activité")

Else

MsgBox ("Activité mise à jour avec succés")

vContact.SaveXml ("C: empContact" + vContact.DocEntry + ".xml")

End If

End If

'Vérification des erreurs

Call vCompany.GetLastError(nErr, errMsg)

If (0 <> nErr) Then

MsgBox ("Found error:" + Str(nErr) + "," + errMsg)

End If

'Déconnexion de lu2019objet Company et liberation des resources

Call vCompany.Disconnect

Set vCompany = Nothing

Exit Sub

ErrorHandler:

MsgBox ("Exception:" + Err.Description)

End Sub

********************************************************************************

but each time I am trying to excute it the follozing error occur "error found: -5002 BP code not valid (OCLG.CardCode)" although the card code I am using qlreqdy exist in the BP table

can you please advise

Best Regards