Skip to Content
author's profile photo
Former Member

DI: Create User Defined Fields fails if I create a company by cookie

Hi,

I cannot create user defined fields through SDK 6.50.52, if I create the connection to the company through the cookie of UI.

I only can, if I create the connection to the company using the standard connect by putting all the information. (Server, Database, User, Password, etc.)

Thanks,

Jorge Neves

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • Best Answer
    author's profile photo
    Former Member
    Mar 22, 2004 at 06:09 AM

    Hi Jorge

    I couldn't reproduce the problem you mentioned.

    I didn't see any difference in the behaviour while adding MetaData objects (Tables and Fields) in both cases.

    1) Connecting to running SAP Business One application using the Single Sign On feature.

    2) Connecting directly to the companyDB with the DI API.

    When SAP Business One application and your addon are both connected to the same DB there isn't any limitation to add MetaData objects with your add-on. In both cases you won't be able to add MetaData objects using SAP Business One application till you'll close your add-on.

    Below I've copied a code sample of connecting with the Single Sign On feature and adding MetaData objects.

    Try to copy this code into simple VB project (to the form code)

    //////////Code Sample////////////////

    Option Explicit

    Public WithEvents SBO_Application As SAPbouiCOM.Application

    Public oCompany As SAPbobsCOM.Company

    Private Sub CmdAddFld_Click()

    Dim RetVal As Long

    Dim ErrCode As Long

    Dim ErrMsg As String

    Dim UFld As SAPbobsCOM.UserFieldsMD

    Set UFld = oCompany.GetBusinessObject(oUserFields)

    UFld.TableName = "TBLC"

    UFld.Name = "Fld1"

    UFld.Description = "Field 1"

    UFld.Type = db_Alpha

    UFld.EditSize = 20

    RetVal = UFld.Add

    If RetVal <> 0 Then

    oCompany.GetLastError ErrCode, ErrMsg

    MsgBox "Failed to add UserField " & ErrCode & " " & ErrMsg

    End If

    End Sub

    Private Sub CmdAddTbl_Click()

    Dim RetVal As Long

    Dim ErrCode As Long

    Dim ErrMsg As String

    Dim UTMD As SAPbobsCOM.UserTablesMD

    Set UTMD = oCompany.GetBusinessObject(oUserTables)

    UTMD.TableName = "TBLC"

    UTMD.TableDescription = "Table C"

    RetVal = UTMD.Add

    If RetVal <> 0 Then

    oCompany.GetLastError ErrCode, ErrMsg

    MsgBox "Failed to add UserTable " & ErrCode & " " & ErrMsg

    End If

    End Sub

    Private Sub Form_Load()

    'Set oHelloWorld = New HelloWorld

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

    '// set SBO_Application with an initialized application object

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

    SetApplication

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

    '// Set The Connection Context

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

    If Not SetConnectionContext = 0 Then

    SBO_Application.MessageBox "Failed setting a connection to DI API"

    End ' Terminating the Add-On Application

    End If

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

    '// Connect To The Company Data Base

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

    If Not ConnectToCompany = 0 Then

    SBO_Application.MessageBox "Failed connecting to the company's Data Base"

    End ' Terminating the Add-On Application

    End If

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

    '// send an "hello world" message

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

    SBO_Application.MessageBox _

    "DI Connected To: " & oCompany.CompanyName _

    & vbNewLine & "Hello World!"

    Form1.Show

    End Sub

    Private Sub SetApplication()

    '*******************************************************************

    '// Use an SboGuiApi object to establish connection

    '// with the SAP Business One application and return an

    '// initialized appliction object

    '*******************************************************************

    Dim SboGuiApi As SAPbouiCOM.SboGuiApi

    Dim sConnectionString As String

    Set SboGuiApi = New SAPbouiCOM.SboGuiApi

    '// by following the steps specified above, the following

    '// statment should be suficient for either development or run mode

    sConnectionString = Command

    '// connect to a running SBO Application

    SboGuiApi.Connect sConnectionString

    '// get an initialized application object

    Set SBO_Application = SboGuiApi.GetApplication()

    End Sub

    Private Function SetConnectionContext() As Long

    Dim sCookie As String

    Dim sConnectionContext As String

    Dim lRetCode As Long

    '// First initialize the Company object

    Set oCompany = New SAPbobsCOM.Company

    '// Acquire the connection context cookie from the DI API.

    sCookie = oCompany.GetContextCookie

    '// Retrieve the connection context string from the UI API using the

    '// acquired cookie.

    sConnectionContext = SBO_Application.Company.GetConnectionContext(sCookie)

    '// Set the connection context information to the DI API.

    SetConnectionContext = oCompany.SetSboLoginContext(sConnectionContext)

    End Function

    Private Function ConnectToCompany() As Long

    '// Establish the connection to the company database.

    ConnectToCompany = oCompany.Connect

    End Function

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi,

      I already found my problem.

      I create the userTable and the userFields on the same function and if I don't set the variable of userTable to nothing this process fails.

      Thanks,

      Jorge Neves

  • author's profile photo
    Former Member
    Mar 24, 2004 at 11:20 AM

    This code sure work in version 6.5

    While Not oRecordset.EOF

    'add an Journal entry

    LineCount = LineCount + 1

    'Call vJE.Lines.SetCurentLine(LineCount)

    vJE.Lines.AccountCode = oRecordset.Fields(0).Value

    ' vJE.Lines.ContraAccount = "10110"

    vJE.Lines.Credit = 0

    vJE.Lines.Debit = Round(oRecordset.Fields(1).Value, 2)

    vJE.Lines.DueDate = oTesto.String 'CDate("11/13/ 2002")

    'vJE.Lines.Line_ID = LineCount

    vJE.Lines.ReferenceDate1 = oTesto.String

    vJE.Lines.ReferenceDate2 = oTesto.String

    'vJE.Lines.ShortName = "110000"

    vJE.Lines.TaxDate = oTesto.String 'Now

    vJE.Lines.LineMemo = oTesto3.String

    Call vJE.Lines.Add

    TotSpese = TotSpese + Round(oRecordset.Fields(1).Value, 2)

    oRecordset.MoveNext

    LineCount = LineCount + 1

    Wend

    ' Call vJE.Lines.SetCurentLine(LineCount)

    vJE.Lines.AccountCode = oTesto2.String

    'vJE.Lines.ContraAccount = "110000"

    vJE.Lines.Credit = TotSpese

    vJE.Lines.Debit = 0

    vJE.Lines.DueDate = oTesto.String

    ' vJE.Lines.Line_ID = LineCount

    vJE.Lines.ReferenceDate1 = oTesto.String

    'vJE.Lines.ShortName = "10110"

    vJE.Lines.TaxDate = oTesto.String

    vJE.Lines.LineMemo = oTesto3.String

    Call vJE.Lines.Add

    If (0 <> vJE.Add()) Then

    WaitEvents.vApp.MessageBox ("Errore nell'inserimento della Prima Nota")

    Else

    Add comment
    10|10000 characters needed characters exceeded