Dynamic Query Using X++

    
         Dynamic querys are used to apply the values in Runtime ,unlike the static querys are the fixed         querys

To create Dynamic Querys In ax we will use following classes.
 
1.QUERY                                             ---------> to create the structre for the query
2.QUERYBUILDDATASOURCE       --------> to add the datasource the query
3.QUERYRANGE                                ----------> to apply ranges
4.QUERYFILTER                                 --------->worked as where class in a standard aql statement
5.QUERYBUILDLINK                        ----------> to add and link two data sources.
6.QUERYHAVINGFILTER                ----------> used for aggregate functions.
 

Example:Filter values By Using Dynamic queries In Ax2012  X++

     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. 


 




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();
}
output;












No comments:

Post a Comment