cancel
Showing results for 
Search instead for 
Did you mean: 

Registration UserObjectsMD by way of code

Former Member
0 Kudos

Hi all, i have a problem

i Creating User Business Object, one header Table and three table Documents

header Table = "@SLSL_ADDITIONALEXP"

1 table Documents = "@SLSL_ADDITIONALSTR"

2 table Documents = "@SLSL_ADDITIONALPAR"

3 table Documents = "@SLSL_ADDITIONALORD"

Code C#

SAPbobsCOM.UserObjectsMD uo = (SAPbobsCOM.UserObjectsMD)Sbo.Instance.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserObjectsMD);

uo.Code = "UDOAddEx";

uo.Name = "AdditionalExpenses";

uo.ObjectType = SAPbobsCOM.BoUDOObjType.boud_Document;

uo.TableName = "@SLSL_ADDITIONALEXP";

uo.Add();

uo.ChildTables.TableName = "@SLSL_ADDITIONALSTR";

uo.ChildTables.Add();

uo.ChildTables.TableName = "@SLSL_ADDITIONALPAR";

uo.ChildTables.Add();

uo.ChildTables.TableName = "@SLSL_ADDITIONALORD";

uo.ChildTables.Add();

where

Sbo.Instance.Company.GetBusinessObject(...);

home function and he work is correct

but Business Object do not creatind

please advice what might be the problem?

Accepted Solutions (1)

Accepted Solutions (1)

barend_morkel2
Active Contributor
0 Kudos

Here is VB Code..

'1. Add Tables

AddUserTable("SM_OMOR", "Meal Order", SAPbobsCOM.BoUTBTableType.bott_Document)

AddUserTable("SM_MOR1", "Meal Lines", SAPbobsCOM.BoUTBTableType.bott_DocumentLines)

Private Sub AddUserTable(ByVal Name As String, ByVal Description As String, _

ByVal Type As SAPbobsCOM.BoUTBTableType)

'//****************************************************************************

'// The UserTablesMD represents a meta-data object which allows us

'// to add\remove tables, change a table name etc.

'//****************************************************************************

Dim oUserTablesMD As SAPbobsCOM.UserTablesMD

'//****************************************************************************

'// In any meta-data operation there should be no other object "alive"

'// but the meta-data object, otherwise the operation will fail.

'// This restriction is intended to prevent a collisions

'//****************************************************************************

'// the meta-data object needs to be initialized with a

'// regular UserTables object

oUserTablesMD = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserTables)

'//**************************************************

'// when adding user tables or fields to the SBO DB

'// use a prefix identifying your partner name space

'// this will prevent collisions between different

'// partners add-ons

'//

'// SAP's name space prefix is "BE_"

'//**************************************************

'// set the table parameters

oUserTablesMD.TableName = Name

oUserTablesMD.TableDescription = Description

oUserTablesMD.TableType = Type

'// Add the table

'// This action add an empty table with 2 default fields

'// 'Code' and 'Name' which serve as the key

'// in order to add your own User Fields

'// see the AddUserFields.frm in this project

'// a privat, user defined, key may be added

'// see AddPrivateKey.frm in this project

lRetCode = oUserTablesMD.Add

'// check for errors in the process

If lRetCode <> 0 Then

If lRetCode = -1 Then

Else

oCompany.GetLastError(lRetCode, sErrMsg)

MsgBox(sErrMsg)

End If

Else

MsgBox("Table: " & oUserTablesMD.TableName & " was added successfully")

End If

oUserTablesMD = Nothing

GC.Collect() 'Release the handle to the table

End Sub

'2. Add Fields

'As per usual

'3. Add UDO

Dim oUserObjectMD As SAPbobsCOM.UserObjectsMD

oUserObjectMD = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserObjectsMD)

oUserObjectMD.CanCancel = SAPbobsCOM.BoYesNoEnum.tYES

oUserObjectMD.CanClose = SAPbobsCOM.BoYesNoEnum.tYES

oUserObjectMD.CanCreateDefaultForm = SAPbobsCOM.BoYesNoEnum.tNO

oUserObjectMD.CanDelete = SAPbobsCOM.BoYesNoEnum.tYES

oUserObjectMD.CanFind = SAPbobsCOM.BoYesNoEnum.tYES

oUserObjectMD.CanYearTransfer = SAPbobsCOM.BoYesNoEnum.tYES

oUserObjectMD.ChildTables.TableName = "SM_MOR1"

oUserObjectMD.Code = "SM_MOR"

oUserObjectMD.ManageSeries = SAPbobsCOM.BoYesNoEnum.tYES

oUserObjectMD.Name = "SM_Meal_Order"

oUserObjectMD.ObjectType = SAPbobsCOM.BoUDOObjType.boud_Document

oUserObjectMD.TableName = "SM_OMOR"

lRetCode = oUserObjectMD.Add()

If lRetCode <> 0 Then

If lRetCode = -1 Then

Else

oCompany.GetLastError(lRetCode, sErrMsg)

MsgBox(sErrMsg)

End If

Else

MsgBox("UDO: " & oUserObjectMD.Name & " was added successfully")

End If

oUserObjectMD = Nothing

Former Member
0 Kudos

thanks, Barend Morkel

Answers (1)

Answers (1)

FOA
Advisor
Advisor
0 Kudos

Hi Gennadiy,

You have to add the UDO after setting the child tables. Please be sure that the tables already exist in the DB.

Best regards,

Felipe

Former Member
0 Kudos

thanks, Felipe.