Friday, May 25, 2012

Filtering multi select dialog based on another multi select dialog


Hello,

We have already done filtering a dialog based on another dialog. We are doing it again but with one difference which is now we are using multi select drop down.

In this post I am taking the same example which I used in my previous post. However, I've now made the 2 dialogs as multi-select which I already discussed in my first post. you can check it here.



After changing the single select dialog box to multi select, I first declared a List variable in the class declaration method. i.e.,

    List selectedGroup;





This selectedGroup variable holds the values of customer groups which were selected by the user.



I also created a method custGroupModified in my custReportUIBuilder class. Since the modified event do not work with multi select dialogs, so I am changing it to leave event. So first I changed the custGroupMidified method to custGroupLeave and put the following code in it

public boolean custGroupLeave(FormStringControl _control)

{

    if (_control.valueStr() != '')

    {

        selectedGroup = strSplit(_control.valueStr(), ';');

        dialogCustGroup.value(selectedGroup);

    }

    return true;

}



Now in the custLookup method we will use the selectedGroup list variable to filter the customers. So, adding the following code in the method:

    if (selectedGroup)

    {

        enum = selectedGroup.getEnumerator();

        while (enum.moveNext())

        {

            query.dataSourceTable(tableNum(CustTable)).addRange(fieldNum(CustTable, CustGroup)).value(enum.current());

        }

    }



Where the variable enum is the list enumerator and which is defined in the method as:

    ListEnumerator enum;



The whole method will look like this:

public void lookupCust(FormStringControl _control)

{

    Query query = new Query();

    container cnt;

    ListEnumerator enum;

   

    query.addDataSource(tableNum(CustTable));

    query.dataSourceTable(tableNum(CustTable)).fields().addField(fieldNum(CustTable, AccountNum));

    query.dataSourceTable(tableNum(CustTable)).fields().addField(fieldNum(CustTable, Party));

   

    if (selectedGroup)

    {

        enum = selectedGroup.getEnumerator();

        while (enum.moveNext())

        {

            query.dataSourceTable(tableNum(CustTable)).addRange(fieldNum(CustTable, CustGroup)).value(enum.current());

        }

    }

    SysLookupMultiSelectGrid::lookup(query, _control, _control, cnt);

}



One last thing is to change the override method of dialogCustGroup’s leave method. I’ll do it in the postBuild method:

    dialogCustGroup.registerOverrideMethod(methodStr(FormStringControl, leave), methodStr(custReportUIBuilder, custGroupLeave), this);



and the whole method will look like this:

public void postBuild()

{

    super();

    // From binding info, get the dialog field for racecode attribute and add button

    dialogCustGroup = this.bindInfo().getDialogField(

                         this.dataContractObject(),

                         methodStr(custReportContract,parmCustGroup));

    // register override method for lookup cust Group

    dialogCustGroup.registerOverrideMethod(methodStr(FormStringControl, lookup), methodStr(custReportUIBuilder, lookupCustGroup), this);

    // register override method for modified

    dialogCustGroup.registerOverrideMethod(methodStr(FormStringControl, leave), methodStr(custReportUIBuilder, custGroupLeave), this);

   

    if (dialogCustGroup)

    {

     dialogCustGroup.lookupButton(2);

    }



    //binding info for customer drop down

    dialogCust = this.bindInfo().getDialogField(

                         this.dataContractObject(),

                         methodStr(custReportContract,parmCust));

   

    // register override method for lookup customer

    dialogCust.registerOverrideMethod(methodStr(FormStringControl, lookup), methodStr(custReportUIBuilder, lookupCust), this);

   

    if (dialogCust)

    {

        dialogCust.lookupButton(2);

    }



}



That’s it, we are now done. Thank you all


1 comment: