ChooseFromList on User Defined Form ( SDK & XML )
Objective: To make CFL on User Defined Form through SDK and XML
The Choose from List is a basic functionality in the SAP Business One application that lets the user open a ChooseFromList form by clicking a trigger item.
Hereby I post the part of source code related to CFL for your reference.
1) Declare the uqniqueid for CFL and declare the Object ID where you are collecting data from.
SDK :
in Form Load Event:
Dim ocfls As SAPbouiCOM.ChooseFromListCollection
ocfls = oForm.ChooseFromLists
Dim ocfl As SAPbouiCOM.ChooseFromList
Dim cflcrepa As SAPbouiCOM.ChooseFromListCreationParams
cflcrepa = oApplication.CreateObject(SAPbouiCOM.BoCreatableObjectType.
cot_ChooseFromListCreationParams)
cflcrepa.MultiSelection = False
cflcrepa.ObjectType = “2”
cflcrepa.UniqueID = “CFL1”
ocfl = ocfls.Add(cflcrepa)
XML:
<ChooseFromListCollection>
<action type=”add”>
<ChooseFromList UniqueID=”CFL1″ ObjectType=”2″ MultiSelection=”0″ IsSystem=”0″/>
</action>
</ChooseFromListCollection>
Here, the sample code objecttype “2” for Business Partner Master Data.
2) Assign the uniqueid and alias into your field.
SDK:
in Form Load Event
Dim oEdit As SAPbouiCOM.EditText
oEdit = oForm.Items.Item(“t_cardcode”).Specific
oEdit.ChooseFromListUID = “CFL1”
oEdit.ChooseFromListAlias = “CardCode”
XML:
<item uid=”t_cardcode” type=”16″ …… supp_zeros=”0″ AffectsFormMode=”1″>
<AutoManagedAttribute/>
<specific TabOrder=”6″ ChooseFromListUID=”CFL1″ ChooseFromListAlias=”CardCode” IsPassword=”0″>
<databind databound=”1″ table=”@INPR_OTRN” alias=”U_CardCode”/>
</specific>
</item>
Be sure your field is alphanumeric type. Here ChooseFromListAlias is “CardCode”. Find option is working based on this ChooseFromListAlias.
3) for Filtration
SDK:
in GOT_FOCUS Event:
If pVal.BeforeAction = False And pVal.ItemUID = “t_cardcode” Then
‘ Adding Conditions to CFL1
Dim oCFL As SAPbouiCOM.ChooseFromList = oForm.ChooseFromLists.Item(“CFL1”) Dim oCons As SAPbouiCOM.Conditions
Dim oCon As SAPbouiCOM.Condition
oCons = oCFL.GetConditions()
oCon = oCons.Add()
oCon.Alias = “CardType”
oCon.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL
oCon.CondVal = “C”
oCFL.SetConditions(oCons)
End If
XML:
<ChooseFromList UniqueID=”CFL1″ ObjectType=”2″ MultiSelection=”0″ IsSystem=”0″>
<conditions>
<condition bracket_open_num=”1″ bracket_close_num=”1″ cond_end_val=”” cond_value=”C” operation=”1″ relationship=”0″ compare_fields=”0″ alias=”CardType” compared_field_alias=””/>
</conditions>
</ChooseFromList>
Here the condition is card type equal customer. So It will list out only Customer nore Supplier and Lead.
Most of the guys are struggling in Filtration part. So here I give more clarification with sample source.
In the conditional part each operations and relationships are having unique id.
Operations:
SAPbouiCOM.BoConditionOperation.co_EQUAL = 1
co_BETWEEN=11
co_CONTAIN=7
co_END=10
co_GRATER_EQUAL=4
co_GRATER_THAN=2
co_IS_NULL=13
co_LESS_EQUAL=5
co_LESS_THAN=3
co_NONE=0
co_NOT_BETWEEN=12
co_NOT_CONTAIN=8
co_NOT_EQUAL=6
co_NOT_NULL=14
co_START=9
Relationships :
SAPbouiCOM.BoConditionRelationship.cr_OR=99
cr_NONE=0
cr_AND=98
Suppose if you want to filter the data based on your own query…
SDK:
Dim oCFL As SAPbouiCOM.ChooseFromList = oForm.ChooseFromLists.Item(“CFL1”)
Dim oConds As SAPbouiCOM.Conditions
Dim oCond As SAPbouiCOM.Condition
Dim oEmptyConds As New SAPbouiCOM.Conditions
Dim rsetCFL As SAPbobsCOM.Recordset = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
oCFL.SetConditions(oEmptyConds)
oConds = oCFL.GetConditions()
rsetCFL.DoQuery(“SELECT CardCode FROM OCRD WHERE CardCode IN (SELECT CardCode FROM ORDR)”)
rsetCFL.MoveFirst()
For i As Integer = 1 To rsetCFL.RecordCount
If i = (rsetCFL.RecordCount) Then
oCond = oConds.Add()
oCond.Alias = “CardCode”
oCond.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL
oCond.CondVal = Trim(rsetCFL.Fields.Item(0).Value)
Else
oCond = oConds.Add()
oCond.Alias = “CardCode”
oCond.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL
oCond.CondVal = Trim(rsetCFL.Fields.Item(0).Value)
oCond.Relationship = SAPbouiCOM.BoConditionRelationship.cr_OR
End If
rsetCFL.MoveNext()
Next
If rsetCFL.RecordCount = 0 Then
oCond = oConds.Add()
oCond.Alias = “CardCode”
oCond.Relationship = SAPbouiCOM.BoConditionRelationship.cr_NONE
oCond.CondVal = “-1”
End If
oCFL.SetConditions(oConds)
XML:
The below sample xml describing two conditions that cardtype equal to customer and balance greater than zero.
<ChooseFromList UniqueID=”CFL1″ ObjectType=”2″ MultiSelection=”0″ IsSystem=”0″>
<conditions>
<condition bracket_open_num=”1″ bracket_close_num=”1″ cond_end_val=”” cond_value=”C” operation=”1″ relationship=”98″ compare_fields=”0″ alias=”CardType” compared_field_alias=””/>
<condition bracket_open_num=”1″ bracket_close_num=”1″ cond_end_val=”” cond_value=”0″ operation=”2″ relationship=”0″ compare_fields=”0″ alias=”Balance” compared_field_alias=””/>
</conditions>
</ChooseFromList>
4) The final step is to set the value into your fields
SDK:
in Choose_From_List Event:
Dim oDataTable As SAPbouiCOM.DataTable
Dim oCFLE As SAPbouiCOM.ChooseFromListEvent = pVal
oDataTable = oCFLE.SelectedObjects
If Not oDataTable Is Nothing And pVal.BeforeAction = False Then
If pVal.ItemUID = “t_cardcode” Then
oDBDSHeader.SetValue(“U_CardCode”, 0, Trim(oDataTable.GetValue(“CardCode”, 0)))
‘oForm.Items.Item(pVal.ItemUID).Specific.value = Trim(oDataTable.GetValue(“CardCode”, 0))
End If
End If
I hope this will help to someone.
Advice to correct this blog is most welcome
Thanks & Regards,
Silambu
Hi,
Thanks for sharing!
It is very useful for beginners.
Regards,
Vinoth