cancel
Showing results for 
Search instead for 
Did you mean: 

This entry already exists in the following tables (ODBC -2035)

darren_grayson
Explorer
0 Kudos

I have a usertable and I am trying to add a record to it. The usertable isn't linked to an object.

Some times this works fine, other times I get error "This entry already exists in the following tables (ODBC -2035)". I have of course checked that the record does not already exist!

Here is my code. "Echo" is a function that makes a debugging log, the log appears below.


'sParentItemKey = item key e.g. "B1000"
'LastRowNumber = integer
'key in 'OCHBOSCL' table will be in form "B1000.1"

'add a new record to the child table
Echo("Need to add new row")
'
Dim oUDT As SAPbobsCOM.UserTable
oUDT = oCompany.UserTables.Item("OCHBOSCL")
Echo("oUDT status: " & oUDT.GetAsXML.ToString & vbCrLf & "Table/code: " & oUDT.TableName.ToString & " " & oUDT.Code.ToString)
'
LastRowNumber = LastRowNumber + 1
Dim sUDTKey As String = sParentItemKey & "." & LastRowNumber
Echo(vbTab & "New OCHBOSCL key=" & sUDTKey)
oUDT.Code = sUDTKey
'
oEdit = oColumns.Item("ChildName").Cells.Item(Row).Specific()
sValue = Trim(oEdit.Value)
Echo(vbTab & "Name = " & sValue)
oUDT.Name = sValue
'
oUDT.UserFields.Fields.Item("U_Parent").Value = sParentItemKey
'
oEdit = oColumns.Item("ChildItm").Cells.Item(Row).Specific()
sValue = Trim(oEdit.Value)
Echo(vbTab & "U_ChildItm = " & sValue)
oUDT.UserFields.Fields.Item("U_ChildItm").Value = sValue
'
'I also update a couple more user fields here as above, removed for clarity
'
Echo("udt code before .add = " & oUDT.Code.ToString)
Echo("udt XML before .add = " & oUDT.GetAsXML.ToString)
'
Dim AddResult As Integer = oUDT.Add
Echo("Add UDT = " & AddResult)
'
Echo("udt code after .add = " & oUDT.Code.ToString)
Echo("udt XML after add = " & oUDT.GetAsXML.ToString)
'
If AddResult = -2035 Then
    Echo("2035 bug")
End If
'
If AddResult = 0 Then
    Echo("Record Added. Key is: " & oCompany.GetNewObjectKey())
Else
    Echo("Add record error: " & oCompany.GetLastErrorCode & ": " & oCompany.GetLastErrorDescription.ToString)
End If


Need to add new row
oUDT status: <?xml version="1.0" encoding="UTF-16"?><BOM><BO><AdmInfo><Object>-3</Object></AdmInfo><OCHBOSCL/></BO></BOM>
Table/code: OCHBOSCL 

	New OCHBOSCL key=B1000.1
	Name = Boxing Gloves
	U_ChildItm = A1000

udt code before .add = B1000.1
udt XML before .add = <?xml version="1.0" encoding="UTF-16"?><BOM><BO><AdmInfo><Object>-3</Object></AdmInfo><OCHBOSCL><row><Code>B1000.1</Code><Name>Boxing Gloves</Name><U_Parent>B1000</U_Parent><U_ChildItm>A1000</U_ChildItm><U_Quantity>99</U_Quantity><U_Prefer>N</U_Prefer><U_Mand>N</U_Mand></row></OCHBOSCL></BO></BOM>

Add UDT = -2035

udt code after .add = B1000.1
udt XML after add = <?xml version="1.0" encoding="UTF-16"?><BOM><BO><AdmInfo><Object>-3</Object></AdmInfo><OCHBOSCL><row><Code>B1000.1</Code><Name>Boxing Gloves</Name><U_Parent>B1000</U_Parent><U_ChildItm>A1000</U_ChildItm><U_Quantity>99</U_Quantity><U_Prefer>N</U_Prefer><U_Mand>N</U_Mand></row></OCHBOSCL></BO></BOM>

2035 bug

Add record error: -2035: This entry already exists in the following tables (ODBC -2035)

You can see from the debug log that the data is being copied into the usertable object as it appears in the XML for the usertable. I tried adding a ".update" after .add but this didn't work. The data is definately not being added to the database.

Does SBO have some sort of key index that could have an old reference to a record with the same key on it?

I've been looking at this for hours, looked at loads of other examples and I just can't see the problem.

Thanks for any help you can offer.

Darren

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello Darren

Probably the counter of the object who uses not this one synchronized.

Looks in the table ONNM at the value of the field AutoKey correspondent to the object where you add

This value has to be like (+1) the last record got in the principal table

Answers (1)

Answers (1)

Trinidad
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Darren,

I'm a bit lost in your message.

Are you sure you are adding a different Code and name for you new record?

Regards

Trinidad.

darren_grayson
Explorer
0 Kudos

Yes, I am sure I am adding a different code.

For example, I have two existing records with codes 'A1001.1' and 'A1001.2'. I get the error when I try to add a new record with code 'B1000.1'.

Thanks,

Darren