Wednesday, July 29, 2020

How to Filter Values by using Dynamic Queries In Ax 2012 X++

Hi guys, Happy Friendship day to all.

To day we see how to filter values using Dynamic Queries.
I Take example like Filtering Purchase Orders of vendor Account. For that I gave VendAccount Number And Status. Depending up on my input values it filter the data from PurchTable And it insert Data in my customized Temporary Table.

Simple list Form:
        


Write Below code Button Clicked method:

void clicked()
{

    Query query = new Query();
    QueryBuildDataSource qbds;
    QueryBuildRange qbr,Qbr1;
    QueryRun qr;
    PurchTable purchTable;

    if (StringEdit.valueStr() )//Sting field name(Auto Declaration --YES) 
    {
        qbds=query.addDataSource(tableNum(purchTable));
        qbr = qbds.addrange(fieldnum(purchTable,OrderAccount));
        qbr.value(StringEdit.valueStr());

        if (ComboBox.valueStr())//Sting field name
        {
            qbr1 = qbds.addrange(fieldnum(purchTable, PurchStatus));
            qbr1.value(ComboBox.valueStr());
        }
    }

    else
    {
        qbds=query.addDataSource(tableNum(purchTable));
        qbr1 = qbds.addrange(fieldnum(purchTable, PurchStatus));
        qbr1.value(ComboBox.valueStr());
    }
    qr = new QueryRun(query);

    while (qr.next())
    {
        purchTable = qr.get(tablenum(PurchTable));
        DAXPurchTable.PurchaseOrder = purchTable.PurchId;
        DAXPurchTable.VendorAccount= purchTable.OrderAccount;
        DAXPurchTable.PurchStatus = purchTable.PurchStatus;

        DAXPurchTable.Insert();

    }

    DAXPurchTable_ds.executeQuery();
}

If we have apply any dates Like from date and To date:
        qbr2 = qbds.addrange (fieldnum(PurchTable,DeliveryDate));
        qbr2.value(SysQuery::range(DateEdit.datevalue(),DateEdit1.datevalue()));

If we want to apply Any EnumType values:
         qbr3 = qbds.addrange (fieldnum(PurchTable,DocumentStatus));
         qbr3 .value(SysQuery::value(DocumentStatus::Invoice));


Output:





Keep Daxing !!

No comments:

Post a Comment