cancel
Showing results for 
Search instead for 
Did you mean: 

Adding record on UDT with UDO

Former Member
0 Kudos

Hi All,

I have this AddOn, which im using a UDT and registered it in UDO. My UDT's object type is MasterData.

On the saving part, i wasnt able to add a record and keep on getting this error: "Master Data Type UserTable can not add row" please tell me why..

'i have this code on the saving part:

Private Sub AddProdHierarchyToDatabase()

Dim ut As SAPbobsCOM.UserTable

Dim uts As SAPbobsCOM.UserTables

Dim rs As SAPbobsCOM.Recordset

Dim sql As String = String.Empty

Dim lastCode As Integer

Try

'get last code

rs = _company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)

sql = "Select COUNT(Code) As LastCode From dbo.[@SMC_ProdHierarchy]"

rs.DoQuery(sql)

lastCode = rs.Fields.Item("LastCode").Value + 1

uts = _company.UserTables

ut = uts.Item("SMC_ProdHierarchy")

ut.Code = lastCode

ut.Name = "6"

ut.UserFields.Fields.Item("U_lookupCode").Value = Module1.HierarchyCode

ut.Add()

ut.Update()

Catch ex As Exception

End Try

End Sub

-Roger

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Why do you do call both Add and Update :

ut.Add()

ut.Update()

Add is to insert a new line in the table, Update is to modify an existing row. You should only call the Add method in this case.

Former Member
0 Kudos

oh yes, sorry bout that. please just disregard the update. tnx!

Answers (1)

Answers (1)

Former Member
0 Kudos

Does your MasterData object also have child tables?

Or is there a field in the MasterData table that is mandatory and you are not filling in ?

There might be another reason: your table is used for the MD object . I don't think you can modify just the table, because that would corrupt the database. You should add values for that object ( these values will be placed in the MD table ) either by allowing the object to have a default form or by using the DI API to add object values by code ( see the first thread in the Sap B1 Sdk forum - "DI API for UDO !!!") .

Edited by: Tibi Ionel on Mar 11, 2009 1:35 PM