cancel
Showing results for 
Search instead for 
Did you mean: 

Regarding Database code of type document object

Former Member
0 Kudos

hi,

i created one sample application in SAP B1 SDK. I created one form using Screen Painter which consist of Book ID(Text field), Book Name(Text field) and a Add Command(Button). I created the database of type Document object. I created two fields in the usertable "BK_DATA" of type document object. I created userdefined-object "BKD" for the table BK_DATA. When i click Add button the event is triggering but it not accepting the usertable what i created when i checked in the debug mode. The code what i have written is

Private Function AddBookToDatabase(ByVal Code As String, ByVal Name As String) As Boolean

Dim Res As Integer

Dim oUsrTbl As SAPbobsCOM.Documents

oUsrTbl = oCompany.UserTables.Item("BK_DATA")

AddBookToDatabase = False

'oUsrTbl.Code = CInt(Code)

'oUsrTbl.Name = Name

oUsrTbl.UserFields.Fields.Item("U_ID").Value = Code

oUsrTbl.UserFields.Fields.Item("U_NAME").Value = Name

Res = oUsrTbl.Add()

If Res = 0 Then

AddBookToDatabase = True

Else

SBO_Application.MessageBox("Error, failed to add movie")

End If

End Function

Accepted Solutions (0)

Answers (1)

Answers (1)

Nussi
Active Contributor
0 Kudos

Hi,

you can't use the UserTable Object for Tables of type master_data or document_data.

UDOs can only be accessed via UIAPI.

the UserTable Object is for Tables of type no_object

lg David

Former Member
0 Kudos

can u tell me how to write code for that in UIAPI. Its urgent

Nussi
Active Contributor
0 Kudos

i can you refer to a good example.

look in C:\Programme\SAP\SAP Business One SDK\Samples\UDO\BlanketAgreement\GUI

for the FrmBlanket.vb

there is a function called DrawForm where a Form is created and bind to a UDO

EDIT:

have a look there - if you need more help i'll try my best

lg David

Former Member
0 Kudos

can i insert data directly into table. what is the code for that in .net

Nussi
Active Contributor
0 Kudos

no - thats the point: with DIAPI it's not possible to fill a UDO.

thats why i refered you to the UIAPI sample.

iam sorry

lg David

Former Member
0 Kudos

im geeting invalid field value in the line

Private Function AddBookToDatabase(ByVal Code As String, ByVal Name As String, ByVal Stock As String) As Boolean

' Dim oRecordSet As SAPbobsCOM.Recordset

Dim oUsrTbl As SAPbobsCOM.UserTable

'Dim oUsrTbl As SAPbobsCOM.Recordset

Dim sSQL As String

Dim Res As Integer

'Dim oUsrTbl As SAPbobsCOM.Items

' sSQL = "SELECT U_bookid,U_bookname FROM [@BK_DATA] WHERE U_bookid='" & Code & "'"

'oUsrTbl = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)

'oUsrTbl = oCompany.UserTables.Item("BKD")

'Try

'oUsrTbl.DoQuery(sSQL)

'Catch ex As Exception

' MessageBox.Show(ex.Message)

'End Try

AddBookToDatabase = False

Try

oUsrTbl = oCompany.UserTables.Item("BK_DATA")

oUsrTbl.Code = CInt(Code)

oUsrTbl.Name = Name

oUsrTbl.UserFields.Fields.Item("Stock").Value = Stock----


(Error Line)

'oUsrTbl.UserFields.Fields.Item("U_SPACE").Value = Space()

Res = oUsrTbl.Add()

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

AddBookToDatabase = False

'oUsrTbl.Code = CInt(Code)

'oUsrTbl.Name = Name

''oUsrTbl.UserFields.Fields.Item("U_").Value = Code

''oUsrTbl.UserFields.Fields.Item("U_NAME").Value = Name

'Res = oUsrTbl.Command.Execute()

If Res = 0 Then

AddBookToDatabase = True

Else

SBO_Application.MessageBox("Error, failed to add movie")

End If

End Function

Nussi
Active Contributor
0 Kudos

it's like petr wrote in the other thread.

change the code to oUsrTbl.UserFields.Fields.Item("U_Stock").Value

but remember -> this only works when your table is type no_object

lg David