Skip to Content
author's profile photo Former Member
Former Member

Creating a User Table via DI API

Hi all,

I'm using

SAP Business One 2004A (6.70.185) SP: 00 PL: 07

and corresponding SAP Business One DI API 2004

I want to create a user table.

I try to create it this way:

I have two functions

First function to create the table

Private Function AP_AddOn_CreateTable() As Boolean

AP_AddOn_CreateTable = True

Dim oUDT As SAPbobsCOM.UserTablesMD

Dim sErrMsg As String

Dim iErrCode As Integer

Dim iReturn As Integer

oUDT = oDIComp.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserTables)

oUDT.TableName = "AP_tbItemCalc"

oUDT.TableDescription = "ItemCalculation"

iReturn = oUDT.Add

If iReturn <> 0 Then

oDIComp.GetLastError(iErrCode, sErrMsg)

Message…

AP_AddOn_CreateTable = False

End If

oUDT = Nothing

End Function

This works fine

Then I call a second function to create the user fields

Private Function AP_AddOn_CreateFields() As Boolean

AP_AddOn_CreateFields = False

Dim oUDF As SAPbobsCOM.UserFieldsMD

Dim sErrMsg As String

Dim iErrCode As Integer

Dim iReturn As Integer

oUDF = oDIComp.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields)

oUDF.TableName = "@AP_tbItemCalc"

'Field1

oUDF.Name = "ItemCode"

oUDF.Description = "ItemCode"

oUDF.Type = SAPbobsCOM.BoFieldTypes.db_Alpha

oUDF.Size = 20

iReturn = oUDF.Add()

If iReturn <> 0 Then

oDIComp.GetLastError(iErrCode, sErrMsg)

Message…

Exit Function

End If

'Field2

oUDF.Name = "ItemName"

oUDF.Description = "ItemName"

oUDF.Type = SAPbobsCOM.BoFieldTypes.db_Alpha

oUDF.Size = 100

iReturn = oUDF.Add()

If iReturn <> 0 Then

oDIComp.GetLastError(iErrCode, sErrMsg)

Message

Exit Function

End If

next fields …

AP_AddOn_CreateFields = True

End Function

The second function returns on adding the first field, an error, errCode -1120, errMsg ‚Ref count for this object is higher than 0’

If i close the application after creating the table and then restart the application only executing the second function it works.

I also tried the example as provided in ‚MetaDataOperations’ and it shows the same behaviour.

Besides, I’m the only user on the system and no other application is running.

Kind regards,

Eduard

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Feb 09, 2005 at 06:29 PM

    Hi,

    See di-add-userfield-to-usertable

    HTH

    Ribeiro Santos

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.