Combo box filtering

Hello Experts,

I have a form which has a combo box whihc has all salesId value and a sample grid to populate the filtered Items based on salesId

I am filling up all the combo box values i.e. salesId in the init method.

public class FormRun extends ObjectRun
{

CustAccount custAccount;
QueryBuildDataSource qbds;
QueryBuildRange salesLineDataRange;
QueryFilter queryFilter;
//For combo box selection filtering
QueryBuildRange salesLineDataRange1;
QueryBuildDataSource qbd;
Query q;
QueryRun qr;
//End
}

public void init()
{
common common;
object object;
formDataSource formDataSource;
formRun formRun;
int i;
super();
if(element.args() && element.args().caller() && element.args().caller().handle() == className2Id(‘formRun’))
{
formRun = element.args().caller();
for (i = 0; i <= formRun.dataSourceCount(); i++)
{
formDataSource = formRun.datasource(i);
if (formDataSource && formDataSource.table() == tablenum(salesTable)) // Search for specific table
{
salesTable.data(element.args().record());
if(salesTable)
{
custAccount = salesTable.CustAccount;
//LVL_AX00123_AddLinesLomasProducts
while select firstonly10 * from salesTable where SalesTable.custAccount == custAccount
{
LVL_PreviousOrders.add(salesTable.SalesId);
}
q = new Query();
qbd = q.addDataSource(TableNum(SalesLine));
salesLineDataRange1 = qbd.addRange(FieldNum(SalesLine, SalesID));
//END
}
}
}
}
}

public void executeQuery()
{
salesLineDataRange1.value(LVL_PreviousOrders.text());
super();
}

public int selectionChange()
{
int ret;
ret = super();
SalesLine_ds.executeQuery(); //Execute the form datasource query to apply the filter
return ret;
}

I am able to fill up the combobox with all salesId according to the selected customer but I am unable to filter the grid i.e. get all the items based on thse selected sales Id in the combo box

Kindly advice at the earliest

Thanks,

Shankar Iyer :slight_smile:

First of all, let me format your code so we can actually read it. You should do it by yourself next time; it’s in your interest.

public class FormRun extends ObjectRun
{

    CustAccount custAccount;
    QueryBuildDataSource qbds;
    QueryBuildRange salesLineDataRange;
    QueryFilter queryFilter;
    //For combo box selection filtering
    QueryBuildRange salesLineDataRange1;
    QueryBuildDataSource qbd;
    Query q;
    QueryRun qr;
    //End
    }

    public void init()
    {
        common common;
        object object;
        formDataSource formDataSource;
        formRun formRun;
        int i;
        
        super();
        
        if(element.args() && element.args().caller() && element.args().caller().handle() == className2Id('formRun'))
        {
            formRun = element.args().caller();
            for (i = 0; i <= formRun.dataSourceCount(); i++)
            {
                formDataSource = formRun.datasource(i);
                if (formDataSource && formDataSource.table() == tablenum(salesTable)) // Search for specific table
                {
                    salesTable.data(element.args().record());
                    if(salesTable)
                    {
                        custAccount = salesTable.CustAccount;
                        while select firstonly10 * from salesTable
                            where SalesTable.custAccount == custAccount
                        {
                            LVL_PreviousOrders.add(salesTable.SalesId);
                        }
                        q = new Query();
                        qbd = q.addDataSource(TableNum(SalesLine));
                        salesLineDataRange1 = qbd.addRange(FieldNum(SalesLine, SalesID));
                    }
                }
            }
        }
    }

    public void executeQuery()
    {
        salesLineDataRange1.value(LVL_PreviousOrders.text());
        super();
    }

    public int selectionChange()
    {
        int ret;
        ret = super();
        SalesLine_ds.executeQuery(); //Execute the form datasource query to apply the filter
        return ret;
    }
}

It’s seem to me that you’re trying to explicitly fill a combobox because you’re not familiar with the right solution in AX - lookups. If your intention is to get “all sales ID values”, you don’t need any code. Simply use SalesId type for LVL_PreviousOrders and the lookup will be generated for you.

Nevertheless your code doesn’t match your description, because it returns only 10 sales ID instead of all. If that’s your goal, you’ll need some extra work to achieve it. But it’s also questionable whether previous orders == all orders.

In ExecuteQuery() method try another logic to apply the filter.

I will Format my code next time I post here

Well My intention is to show only last 10 sales order for that customer.

My issue doesn’t lie there… Based on the selected value of combo box i.e selected sales order I need to filter the grid below

For example: If I select an order i.e. C0011473 from the list of the 10 previous sales orders for that customer, I should show all related Item Id, Unit price and quantity for the selected combo box value

pastedimage1503060775956v1.png

Any idea how can I achieve this?

Can you specify the logic please?

You’ll “show all related Item Id, Unit price and quantity for the selected combo box value” by building a query with a filter for SalesId field, which value will be taken from the control above the grid.