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

I try add user field to OINV table.

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

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Best Answer
    Posted on Oct 06, 2016 at 01:21 PM

    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)

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 06, 2016 at 01:22 PM
    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.