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

DataBind and ChooseFromList

Hi All,

I'm developing an add-on where I need to create a new Document.

The Metadata operations were kinda easy, and I'm created (through code) all the UDT, UDF and UDO I needed.

Then I created a form using ScreenPainter, the application Menu and so on.

No I'm just lost with the DataBinding. I'll explain

After loading the form, I bind the form fields to the table were I want to save the information. I do this using DBDataSource and it's working.

If pVal.MenuUID = "OONE_fldOONE_mnuNR" And pVal.BeforeAction = False Then

            BubbleEvent = False
            cSup.LoadFromXML(SBO_Application, "frmNR.srf")

            'Get the added form object by using the form's UID
            oForm = SBO_Application.Forms.Item("frmNR")

            'SBO_Application.MessageBox(oForm.DataSources.DBDataSources.Count.ToString)

            AddChooseFromList_NR()

            oForm.Items.Item("U_CardCode").Specific.DataBind.SetBound(True, "@OONE_ONR", "U_OONE_CardCode")
            oForm.Items.Item("U_CardCode").Specific.ChooseFromListUID = "CFL1"
            oForm.Items.Item("U_CardCode").Specific.ChooseFromListAlias = "CardCode"
            oForm.Items.Item("cflBut1").Specific.ChooseFromListUID = "CFL3"

            oForm.Items.Item("U_CardName").Specific.DataBind.SetBound(True, "@OONE_ONR", "U_OONE_CardName")
            oForm.Items.Item("U_RefNumb").Specific.DataBind.SetBound(True, "@OONE_ONR", "U_OONE_RefNumb")
           ...

But now I need to create some ChooseFromLists, get the next document number and so on. The problem starts with the ChooseFromList. I catch the event, I get the values from the DataTable but I can't set this values to the form fields. I get the "Item - Can't set value on item because the item can't get focus" exception.

I read in the forum that this can be solved by setting the value to the datasource in stead of the item, but how can I do this?

I've also tried to use UserDataSources but I can't get it to work...

Can someone provide me an example on how to create a new B1 Document?

Or can someone take a look at my code and point out what I'm doing wrong?

 Private Sub SBO_Application_ItemEvent(ByVal FormUID As String, ByRef pVal As SAPbouiCOM.ItemEvent, ByRef BubbleEvent As Boolean) Handles SBO_Application.ItemEvent

        Select Case pVal.EventType
                'Tratar eventos do tipo ChooseFromList
            Case SAPbouiCOM.BoEventTypes.et_CHOOSE_FROM_LIST

                'Se estamos presente o formulário "Nota de Recepção" e o item é o "U_CardCode"
                If FormUID = "frmNR" And (pVal.ItemUID = "U_CardCode" Or pVal.ItemUID = "cflBut1") Then

                    Dim oCFLEvent As SAPbouiCOM.IChooseFromListEvent = pVal
                    Dim sCFL_ID As String = oCFLEvent.ChooseFromListUID
                    Dim oCFL As SAPbouiCOM.ChooseFromList = oForm.ChooseFromLists.Item(sCFL_ID)

                    Dim oDataTable As SAPbouiCOM.DataTable = oCFLEvent.SelectedObjects
                    Dim CardCode As String
                    Dim CardName As String = ""

                    If oCFLEvent.BeforeAction = False Then
                        Try
                            CardCode = oDataTable.GetValue("CardCode", 0)
                            CardName = oDataTable.GetValue("CardName", 0)
                            ' oForm.DataSources.UserDataSources.Item("U_CardCode").ValueEx = CardCode
                            oForm.Items.Item("U_CardCode").Specific.Value = CardCode
                            oForm.Items.Item("U_CardName").Specific.Value = CardName
                        Catch ex As Exception
                            SBO_Application.MessageBox(ex.Message.ToString)
                        End Try
                    End If
                End If

My Form

MainOrangeOne.vb

OrangeOne.vb

Thanks in advanced.

Best Regards,

Vitor Vieira

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Posted on Apr 07, 2008 at 05:35 PM

    Hi Vitor,

    i think the easiest way to solve the

    "Item - Can't set value on item because the item can't get focus" problem is to shortly disable the item.

    1.disable

    oItem.Enabled = False

    2. set the value

    3. enable

    oItem.Enabled = True

    i hope it helps you - if yes ... 😊

    David

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member David Nussböck

      Hi David,

      Didn't know about that, very handy, Click method but still that was not the answer.

      I was using DBDataSources on every field in my form and than I was sending the value to the item.

      I changed my approach and used UserDataSources and I'm sending the value to the UserDataSource.

      Since there are more people with this problem, I'll post the code here.

      Defining the CFL for the Business Partner Code and Name

      Private Sub AddChooseFromList_NR()
              Try
                  Dim oCFLs As SAPbouiCOM.ChooseFromListCollection
                  Dim oCons As SAPbouiCOM.Conditions
                  Dim oCon As SAPbouiCOM.Condition
                  Dim oCFL As SAPbouiCOM.ChooseFromList
                  Dim oCFLCreationParams As SAPbouiCOM.ChooseFromListCreationParams
      
                  oCFLs = oForm.ChooseFromLists
      
                  oCFLCreationParams = SBO_Application.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_ChooseFromListCreationParams)
      
                  ' Adicionar um CFL (Business Partner CardCode) para a textbox U_CardCode.
                  oCFLCreationParams.MultiSelection = False
                  oCFLCreationParams.ObjectType = "2"
                  oCFLCreationParams.UniqueID = "CFL1" 'Business Parner Code
      
                  oCFL = oCFLs.Add(oCFLCreationParams)
      
                  ' Adicionar condições ao CFL1
                  oCons = oCFL.GetConditions()
      
                  oCon = oCons.Add()
                  oCon.Alias = "CardType"
                  oCon.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL
                  oCon.CondVal = "S"
                  oCFL.SetConditions(oCons)
      
                  ' Adicionar CFL (Business Partner CardCode) para o botão cflBut1
                  oCFLCreationParams.UniqueID = "CFL3"
                  oCFL = oCFLs.Add(oCFLCreationParams)
                  oCFL.SetConditions(oCons)
              Catch
                  MsgBox(Err.Description)
              End Try
          End Sub
      

      Creating the UserDataSources and Binding

      Private Sub SBO_Application_MenuEvent(ByRef pVal As SAPbouiCOM.MenuEvent, ByRef BubbleEvent As Boolean) _
              Handles SBO_Application.MenuEvent
      
              '********************************************************************************
              ' in order to activate your own forms instead of SAP Business One system forms
              ' process the menu event by your self
              ' change BubbleEvent to False so that SAP Business One won't process it
              '********************************************************************************
      
              If pVal.MenuUID = "OONE_fldOONE_mnuNR" And pVal.BeforeAction = False Then
      
                  BubbleEvent = False
                  cSup.LoadFromXML(SBO_Application, "frmNR.srf")
      
                  'Get the added form object by using the form's UID
                  oForm = SBO_Application.Forms.Item("frmNR")
      
                  'oForm.DataSources.DBDataSources.Add("OCRD")
                  'SBO_Application.MessageBox(oForm.DataSources.DBDataSources.Count.ToString)
                  oForm.DataSources.UserDataSources.Add("OONE_CCode", BoDataType.dt_SHORT_TEXT, 15)
                  oForm.DataSources.UserDataSources.Add("OONE_CName", BoDataType.dt_SHORT_TEXT, 100)
                  'oForm.DataSources.UserDataSources.Add("OONE_
      
                  AddChooseFromList_NR()
      
                  oForm.Items.Item("U_CardCode").Specific.DataBind.SetBound(True, "", "OONE_CCode")
                  oForm.Items.Item("U_CardCode").Specific.ChooseFromListUID = "CFL1"
                  oForm.Items.Item("U_CardCode").Specific.ChooseFromListAlias = "CardCode"
                  oForm.Items.Item("cflBut1").Specific.ChooseFromListUID = "CFL3"
      
                  oForm.Items.Item("U_CardName").Specific.DataBind.SetBound(True, "", "OONE_CName")
                  oForm.Items.Item("U_CardName").Specific.DataBind.SetBound(True, "@OONE_ONR", "U_OONE_CardName") --> This is what I was doing wrong...
      
                  ...
                  oForm.Visible = True
      
                  BubbleEvent = True
              End If
      
              If pVal.MenuUID = "OONE_fldOONE_mnuExit" And pVal.BeforeAction = False Then
                  Try
                      oMenu.RemoveEx("OONE_fldOONE") 'this is not working...
                      System.Windows.Forms.Application.Exit()
                  Catch ex As Exception
                      SBO_Application.MessageBox(ex.Message.ToString)
                  End Try
              End If
      
          End Sub
      

      Handling the CFL event

      Case SAPbouiCOM.BoEventTypes.et_CHOOSE_FROM_LIST
      
                      'If we're in the correct form and field
                      If FormUID = "frmNR" And (pVal.ItemUID = "U_CardCode" Or pVal.ItemUID = "cflBut1") Then
      
                          Dim oCFLEvent As SAPbouiCOM.IChooseFromListEvent = pVal
                          Dim sCFL_ID As String = oCFLEvent.ChooseFromListUID
                          Dim oCFL As SAPbouiCOM.ChooseFromList = oForm.ChooseFromLists.Item(sCFL_ID)
      
                          Dim oDataTable As SAPbouiCOM.DataTable = oCFLEvent.SelectedObjects
                          Dim CardCode As String
                          Dim CardName As String = ""
      
                          If oCFLEvent.BeforeAction = False Then
                              Try
                                  CardCode = oDataTable.GetValue("CardCode", 0)
                                  CardName = oDataTable.GetValue("CardName", 0)
                                  oForm.DataSources.UserDataSources.Item("OONE_CCode").ValueEx = CardCode
                                  oForm.DataSources.UserDataSources.Item("OONE_CName").ValueEx = CardName
                                  'oForm.Items.Item("U_CardCode").Specific.Value = CardCode --> This is what I was doing wrong
                                  'oForm.Items.Item("U_CardName").Specific.Value = CardName --> This is what I was doing wrong
                              Catch ex As Exception
                                  SBO_Application.MessageBox(ex.Message.ToString)
                              End Try
                          End If
                      End If
      

      Hope this helps someone avoid the frustration I went through in the past few days...

      Best Regards to all,

      Vítor M. M. Vieira

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.