Search code examples
vb.netsapb1

Multiple Choose From Lists on User Form


I have a custom user form with a working Choose From List which selects CardName from the list of Business Partners and displays in an edit text.

Is it possible to add a second Choose From List to a separate edit text to Choose from the OITM Item Master Table?

The first Clf will only work when the form has the ObjectType Property set to 2 (Business Partners), Does this suggest that it is not possible to have a second cfl for another table on the Form?

When i Remove the property i receive this error: enter image description here

Is there any way around this?

enter image description here


Solution

  • The issue was a missing DBDataSources.Add("OITM")

    For each Choose From List that is required on the form, the relevant SAP table must be added as a dbDatasource

    The complete code for adding multiple Choose From Lists from different object types:

     Dim oForm As SAPbouiCOM.Form = Application.SBO_Application.Forms.Item(Me.UIAPIRawForm.UniqueID)
    
            oForm.DataSources.UserDataSources.Add("udsBpName", SAPbouiCOM.BoDataType.dt_SHORT_TEXT)
    
            Dim oCFLs As SAPbouiCOM.ChooseFromListCollection = oForm.ChooseFromLists
            Dim oCons As SAPbouiCOM.Conditions
            Dim oCon As SAPbouiCOM.Condition
            Dim oCFL As SAPbouiCOM.ChooseFromList
            Dim oCFLCreationParams As SAPbouiCOM.ChooseFromListCreationParams
            oCFLCreationParams = CType(Application.SBO_Application.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_ChooseFromListCreationParams), SAPbouiCOM.ChooseFromListCreationParams)
            oCFLCreationParams.MultiSelection = False
            oCFLCreationParams.ObjectType = "2"
            oCFLCreationParams.UniqueID = "CFL_Name"
            oCFL = oCFLs.Add(oCFLCreationParams)
            oCons = oCFL.GetConditions()
            oCon = oCons.Add()
            oCon.Alias = "CardType"
            oCon.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL
            oCon.CondVal = "C"
            oCFL.SetConditions(oCons)
    
            etBpName.DataBind.SetBound(True, "OCRD", "CardName")
            etBpName.ChooseFromListUID = "CFL_Name"
            etBpName.ChooseFromListAlias = "CardName"
    
    
            ' This Item Master dbDatasource Needs to be added to the form 
            ' Before the Cfl with matching object type (in this case 4) is added 
            oForm.DataSources.DBDataSources.Add("OITM")
    
            Dim oCFLs2 As SAPbouiCOM.ChooseFromListCollection = oForm.ChooseFromLists
            Dim oCons2 As SAPbouiCOM.Conditions
            Dim oCon2 As SAPbouiCOM.Condition
            Dim oCFL2 As SAPbouiCOM.ChooseFromList
            Dim oCFLCreationParams2 As SAPbouiCOM.ChooseFromListCreationParams
            oCFLCreationParams2 = CType(Application.SBO_Application.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_ChooseFromListCreationParams), SAPbouiCOM.ChooseFromListCreationParams)
            oCFLCreationParams2.MultiSelection = False
            oCFLCreationParams2.ObjectType = "4"
            oCFLCreationParams2.UniqueID = "CFL1"
            oCFL2 = oCFLs2.Add(oCFLCreationParams2)
            oCons2 = oCFL2.GetConditions()
            oCon2 = oCons2.Add()
            oCon2.Alias = "Validfor"
            oCon2.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL
            oCon2.CondVal = "Y"
            oCFL2.SetConditions(oCons2)
    
            EditText0.DataBind.SetBound(True, "OITM", "ItemCode")
            EditText0.ChooseFromListUID = "CFL1"
            EditText0.ChooseFromListAlias = "ItemCode"