自定义用户表单添加双Choose From List(CFL)的可行性及报错解决咨询
Absolutely you can add a second CFL for the Item Master (OITM) table to your custom form—you just need to stop relying on the form's global ObjectType property to auto-configure your CFLs. Let me break down the problem and how to fix it:
Why the ObjectType Restriction Seems Like a Block
Your first CFL works when the form's ObjectType is set to 2 (Business Partners) because SAP B1 auto-links the CFL to that business object by default. But when you remove that property, the auto-configured CFL breaks, which is why you get an error. The good news is you don't need to rely on this auto-linking at all.
Step-by-Step Solution
1. Reset the Form's ObjectType
Set your form's ObjectType to -1 (this marks it as a fully custom form, no tied business object). This removes the global binding that was forcing the CFL to only work with Business Partners.
2. Manually Configure Both CFLs
Whether you're using the SAP B1 Form Builder (visual design) or writing SDK code, you can create independent CFLs for each table:
Option A: Using Form Builder (No Code)
- Open your custom form in Form Builder.
- For your Business Partner text box:
- Select the text box, go to the Choose From List property.
- Click the ellipsis to open the CFL configuration window.
- Create a new CFL, set its Object Type to 2 (Business Partners), give it a unique ID like
CFL_BP. - Select the fields you want to display (e.g.,
CardCode,CardName) and set the default return field toCardName.
- For your Item Master text box:
- Repeat the same steps, but set the Object Type to 4 (Items), use a unique ID like
CFL_Item. - Choose fields like
ItemCode,ItemNameand set the return field to your preferred value (e.g.,ItemCodeorItemName).
- Repeat the same steps, but set the Object Type to 4 (Items), use a unique ID like
Option B: Using SDK Code (Programmatic Setup)
If you're building the form via code, you can create and bind CFLs directly:
' Initialize the form first (your existing form setup code here) ' Create Business Partner CFL Dim cflBPParams As SAPbouiCOM.ChooseFromListCreationParams = _ SBO_Application.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_ChooseFromListCreationParams) cflBPParams.UniqueID = "CFL_BP" cflBPParams.ObjectType = "2" ' Business Partner object type cflBPParams.MultiSelection = False Dim cflBP As SAPbouiCOM.ChooseFromList = oForm.ChooseFromLists.Add(cflBPParams) ' Bind to Business Partner text box Dim txtBP As SAPbouiCOM.EditText = oForm.Items.Item("txtCardName").Specific txtBP.ChooseFromListUID = "CFL_BP" ' Create Item Master CFL Dim cflItemParams As SAPbouiCOM.ChooseFromListCreationParams = _ SBO_Application.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_ChooseFromListCreationParams) cflItemParams.UniqueID = "CFL_Item" cflItemParams.ObjectType = "4" ' Item object type cflItemParams.MultiSelection = False Dim cflItem As SAPbouiCOM.ChooseFromList = oForm.ChooseFromLists.Add(cflItemParams) ' Bind to Item text box Dim txtItem As SAPbouiCOM.EditText = oForm.Items.Item("txtItemName").Specific txtItem.ChooseFromListUID = "CFL_Item"
3. Handle CFL Selection Events
You'll need to capture the ChooseFromListEvent to populate the correct text box when a user selects an item. Here's how to distinguish between the two CFLs:
Private Sub SBO_Application_ChooseFromListEvent(ByRef pVal As SAPbouiCOM.ChooseFromListEvent, ByRef BubbleEvent As Boolean) _ Handles SBO_Application.ChooseFromListEvent If pVal.FormUID <> "YourCustomFormUID" Then Return Dim oForm As SAPbouiCOM.Form = SBO_Application.Forms.Item(pVal.FormUID) Dim selectedData As SAPbouiCOM.DataTable = pVal.SelectedObjects If selectedData.Rows.Count = 0 Then Return Select Case pVal.ChooseFromListUID Case "CFL_BP" ' Populate Business Partner text box oForm.Items.Item("txtCardName").Specific.Value = selectedData.GetValue("CardName", 0) ' Optional: Populate CardCode in a hidden field if needed ' oForm.Items.Item("txtCardCode").Specific.Value = selectedData.GetValue("CardCode", 0) Case "CFL_Item" ' Populate Item text box oForm.Items.Item("txtItemName").Specific.Value = selectedData.GetValue("ItemName", 0) ' Optional: Populate ItemCode ' oForm.Items.Item("txtItemCode").Specific.Value = selectedData.GetValue("ItemCode", 0) End Select End Sub
Key Notes
- Always use unique IDs for each CFL to avoid conflicts.
- When using Form Builder, make sure the form's
ObjectTypeis set to-1(Custom) to prevent auto-binding issues. - You can extend this approach to add as many CFLs as needed for different tables (e.g., G/L Accounts, Vendors) on the same form.
内容的提问来源于stack exchange,提问作者Praxiom

