cancel
Showing results for 
Search instead for 
Did you mean: 

I try add user field to OINV table.

Former Member
0 Kudos

Hello,

I'm trying to add user field to OINV and I have a problem.

I Added 4 userfields to user table, after that i want to add one user field to oinv.

Public Class RSE_CreateTable

    Private muc_ParentAddon As ADDONBase

    Private mst_ErrNumber As String

    Private min_ErrMsg As Integer

    Public Sub New(ByRef puc_ParentAddon As ADDONBase)

        muc_ParentAddon = puc_ParentAddon

    End Sub

    Public Sub Create()

        If RSE_AddTable() = False Then

            Exit Sub

        End If

        If RSE_AddField() = False Then

            Exit Sub

        End If

        If RSE_AddObject() = False Then

            Exit Sub

        End If

        Me.muc_ParentAddon.SBO_Application.MessageBox("Tabele dodane")

    End Sub

Private Function RSE_AddField() As Boolean

oUserFieldMD = muc_ParentAddon.SBO_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields)

        If Not oUserFieldMD.GetByKey("@" & RSE_TabelaDokumentLinie.cst_Kal1, 0) Then

            oUserFieldMD.Description = "Długość "

            oUserFieldMD.Name = Mid(RSE_TabelaDokumentLinie.cst_Dlugosc, 3)

            oUserFieldMD.Type = SAPbobsCOM.BoFieldTypes.db_Float

            oUserFieldMD.SubType = SAPbobsCOM.BoFldSubTypes.st_Quantity

            oUserFieldMD.TableName = RSE_TabelaDokumentLinie.cst_Kal1

            oUserFieldMD.Size = 16

            If oUserFieldMD.Add <> 0 Then

                muc_ParentAddon.SBO_Company.GetLastError(min_ErrMsg, mst_ErrNumber)

                muc_ParentAddon.SBO_Application.StatusBar.SetText("Błąd dodawania pola użytkownika U_RSE_Dlugosc. " & mst_ErrNumber, SAPbouiCOM.BoMessageTime.bmt_Long, SAPbouiCOM.BoStatusBarMessageType.smt_Error)

                Return False

                Exit Function

            End If

        End If

        System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserFieldMD)

        oUserFieldMD = muc_ParentAddon.SBO_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields)

        If Not oUserFieldMD.GetByKey("@" & RSE_TabelaDokumentLinie.cst_Kal1, 1) Then

            oUserFieldMD.Description = "Szerokość formatki"

            oUserFieldMD.Name = Mid(RSE_TabelaDokumentLinie.cst_Szerokosc, 3)

            oUserFieldMD.Type = SAPbobsCOM.BoFieldTypes.db_Float

            oUserFieldMD.SubType = SAPbobsCOM.BoFldSubTypes.st_Quantity

            oUserFieldMD.TableName = RSE_TabelaDokumentLinie.cst_Kal1

            oUserFieldMD.Size = 16

            If oUserFieldMD.Add <> 0 Then

                muc_ParentAddon.SBO_Company.GetLastError(min_ErrMsg, mst_ErrNumber)

                muc_ParentAddon.SBO_Application.StatusBar.SetText("Błąd dodawania pola użytkownika U_RSE_Szerokosc" & mst_ErrNumber, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)

                Return False

                Exit Function

            End If

        End If

        System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserFieldMD)

        oUserFieldMD = muc_ParentAddon.SBO_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields)

        If Not oUserFieldMD.GetByKey("@" & RSE_TabelaDokumentLinie.cst_Kal1, 2) Then

            oUserFieldMD.Description = "Ilość szt formatek"

            oUserFieldMD.Name = Mid(RSE_TabelaDokumentLinie.cst_Ilosc, 3)

            oUserFieldMD.Type = SAPbobsCOM.BoFieldTypes.db_Float

            oUserFieldMD.SubType = SAPbobsCOM.BoFldSubTypes.st_Quantity

            oUserFieldMD.TableName = RSE_TabelaDokumentLinie.cst_Kal1

            oUserFieldMD.Size = 16

            If oUserFieldMD.Add <> 0 Then

                muc_ParentAddon.SBO_Company.GetLastError(min_ErrMsg, mst_ErrNumber)

                muc_ParentAddon.SBO_Application.StatusBar.SetText("Błąd dodawania pola użytkownika U_RSE_Ilosc" & mst_ErrNumber, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)

                Return False

                Exit Function

            End If

        End If

        System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserFieldMD)

        oUserFieldMD = muc_ParentAddon.SBO_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields)

        If Not oUserFieldMD.GetByKey("@" & RSE_TabelaDokumentLinie.cst_Kal1, 3) Then

            oUserFieldMD.Description = "Powierzchnia formatek"

            oUserFieldMD.Name = Mid(RSE_TabelaDokumentLinie.cst_Powierzchnia, 3)

            oUserFieldMD.Type = SAPbobsCOM.BoFieldTypes.db_Float

            oUserFieldMD.SubType = SAPbobsCOM.BoFldSubTypes.st_Quantity

            oUserFieldMD.TableName = RSE_TabelaDokumentLinie.cst_Kal1

            oUserFieldMD.Size = 16

            If oUserFieldMD.Add <> 0 Then

                muc_ParentAddon.SBO_Company.GetLastError(min_ErrMsg, mst_ErrNumber)

                muc_ParentAddon.SBO_Application.StatusBar.SetText("Błąd dodawania pola użytkownika U_RSE_Powierzchnia" & mst_ErrNumber, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)

                Return False

                Exit Function

            End If

        End If

        System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserFieldMD)

        oUserFieldMD = muc_ParentAddon.SBO_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields)

        'Invoice = muc_ParentAddon.SBO_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInvoices)

        iIlePol = oInvoice.UserFields.Fields.Count

        If Not oUserFieldMD.GetByKey(RSE_TabeleDokument.cst_OINV, 5) Then

            oUserFieldMD.Description = "Nr pozycji"

            oUserFieldMD.Name = Mid(RSE_TabeleDokument.cst_NrDokF, 3)

            oUserFieldMD.Type = SAPbobsCOM.BoFieldTypes.db_Numeric

            oUserFieldMD.TableName = RSE_TabeleDokument.cst_OINV

            oUserFieldMD.Size = 11

            If oUserFieldMD.Add <> 0 Then

                muc_ParentAddon.SBO_Company.GetLastError(min_ErrMsg, mst_ErrNumber)

                muc_ParentAddon.SBO_Application.StatusBar.SetText("Błąd dodawania pola użytkownik " & RSE_TabeleDokument.cst_NrDokF & " do OINV" & mst_ErrNumber, SAPbouiCOM.BoMessageTime.bmt_Long, SAPbouiCOM.BoStatusBarMessageType.smt_Error)

                Return False

                Exit Function

            End If

        End If

        System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserFieldMD)

        Return True

    End Function

----------------------------------------------------------------------------------

and a fragment of code calling sub

----------------------------------------------------------------------------------

           Dim duc_CreateTable As New RSE_CreateTable(Me)

            Me.SBO_Application.MetadataAutoRefresh = False

            duc_CreateTable.Create()

            Me.SBO_Application.MetadataAutoRefresh = True

            duc_CreateTable = Nothing

----------------------------------------------------------------------------------

When I put code as hare:

----------------------------------------------------------------------------------

        'Invoice = muc_ParentAddon.SBO_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInvoices)

        'iIlePol = oInvoice.UserFields.Fields.Count

        If Not oUserFieldMD.GetByKey(RSE_TabeleDokument.cst_OINV, 5)

when 5 because there is 5 user fields.

error is - field size different from the permitted range [1..11]

When is:

        Invoice = muc_ParentAddon.SBO_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInvoices)

        iIlePol = oInvoice.UserFields.Fields.Count

        If Not oUserFieldMD.GetByKey(RSE_TabeleDokument.cst_OINV, iIlePol)

error is - Ref count for this object is higher then 0

--------------------------------------------------------------------------------------------------------------------------

Please, tell me why can I added 4 fields to UserTable as KAL1 but I can't add user field to OINV?

Thanks for help.

Robert

Accepted Solutions (1)

Accepted Solutions (1)

former_member233854
Active Contributor
0 Kudos

Hi Robert,

You should Release the Inv object before using the UserFieldsMD

Invoice = muc_ParentAddon.SBO_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInvoices)

        iIlePol = oInvoice.UserFields.Fields.Count

System.Runtime.InteropServices.Marshal.ReleaseComObject(Invoice)

        If Not oUserFieldMD.GetByKey(RSE_TabeleDokument.cst_OINV, iIlePol)

Former Member
0 Kudos

Hi Danilo,

You are very helpfull, thanks for You

Regards,

Robert

Answers (1)

Answers (1)

former_member185682
Active Contributor
0 Kudos