Skip to Content
0

Multiple Conditions on Choose From List not working

Apr 12 at 12:09 PM

75

avatar image

I am using the C# UI and DI API for Business One 9.2 PL03 and customizing an User Defined Document (UDT Document + UDT Document Rows --> UDO --> UDO Form). I added a ChooseFromList to a matrix column in B1 Studio, which is working as expected, but I would also like to add two conditions to filter the displayed rows. If I add them separately, they work, but If I add both of them at once, I get no results, event though I can see in SQL Studio that the table contains rows matching the criteria.

This code adds the conditions:

private void OnActionTargetPurchaseOrderChooseFromListBefore(ChooseFromListEvent cflEvent)
{
    try
    {
        oForm.Freeze(true);

        if (cflEvent.ChooseFromListUID.Equals("..."))
        {
            string cflFormUID = cflEvent.FormUID;
            ChooseFromList cfl = oForm.ChooseFromLists.Item("...");
            
            // Clear
            Conditions conds = cfl.GetConditions();
            // static class variable, set once on form load, always contins the empty Conditions
            conds.LoadFromXML(PurchaseOrderChooseFromListDefaultConfitionsAsXml);
            cfl.SetConditions(conds);

            string before = cfl.GetConditions().GetAsXML(); // for debug 
            
            SBOTools.ChooseFromListAddCondition(oForm, ".. CFL", "DocStatus", BoConditionOperation.co_NOT_EQUAL, "C");
            if (cflEvent.Row > -1)
            {
                Matrix oMatrix = (Matrix)oForm.Items.Item("...").Specific;
                oMatrix.FlushToDataSource();
                DBDataSource oDBDataSource = oForm.DataSources.DBDataSources.Item("...");
                string cardCode = oDBDataSource.GetValue(".. CardCode Column", cflEvent.Row - 1).Trim();
                if (!"".Equals(cardCode))
                {
                   SBOTools.ChooseFromListAddCondition(oForm, ".. CFL", "CardCode", BoConditionOperation.co_EQUAL, cardCode);
                }
            }
            string after = cfl.GetConditions().GetAsXML(); // for debug
        }
    }
    catch (Exception e)
    {
        Logger.TraceException(e);
    }
    finally
    {
        if (oForm != null)
            oForm.Freeze(false);
    }
}<br>

The ChooseFromListAddCondition method:

public static void ChooseFromListAddCondition(Form oForm, string cflID, string alias, BoConditionOperation operation, string conditionVal)
{
    ChooseFromList oCfl = oForm.ChooseFromLists.Item(cflID);
    var conditions = oCfl.GetConditions();
    var cond = conditions.Add();
    cond.Alias = alias;
    cond.Operation = operation;
    cond.CondVal = conditionVal;
    oCfl.SetConditions(conditions);
}

Looking the the XMLs, I can see that before the addition, the conditions are always empty and after both of them gets added. The problem is that the Choose From List simply does not contains rows. If I only add the DocStatus or the CardCode condition, the List contains results.

The Choose From List definition:

 <ChooseFromListCollection>
  <action type="add">
    <ChooseFromList UniqueID="-1" ObjectType="-1" MultiSelection="0" IsSystem="1" />
    ....
    <ChooseFromList UniqueID="CFL_4" ObjectType="22" MultiSelection="0" IsSystem="0" />
  </action>
</ChooseFromListCollection>


...

 <column ChooseFromListAlias="DocNum" ChooseFromListIsAutoFill="0" ChooseFromListUID="CFL_4" forecolor="-1" backcolor="-1" text_style="0" disp_desc="0" visible="1" AffectsFormMode="1" val_on="Y" IsAutoGenerated="0" val_off="N" description="C....." title="..." width="100" editable="1" type="116" right_just="0" uid="C_0_7" sortable="1">
  <databind databound="1" table="@..." alias="U_TargetPurOrder" />
  <ExtendedObject linkedObject="22" LinkedObjectType="22" />
</column>
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Edy Simon Apr 13 at 12:39 AM
0

Hi Hi,

You are missing the cond.Relationship property to add more than 1 conditions

Below excerpt of adding 2 conditions:

            Dim oCons As SAPbouiCOM.Conditions = cfl.GetConditions
            Dim oCon As SAPbouiCOM.Condition = oCons.Add
            oCon.BracketOpenNum = 2
            oCon.Alias = "Locked"
            oCon.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL
            oCon.CondVal = "N"
            oCon.BracketCloseNum = 1
            oCon.Relationship = BoConditionRelationship.cr_AND


            oCon = oCons.Add
            oCon.BracketOpenNum = 1
            oCon.Alias = "DimCode"
            oCon.Operation = BoConditionOperation.co_EQUAL
            oCon.CondVal = 1
            oCon.BracketCloseNum = 2

Regards
Edy

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Thank you!

0