Get the ranges and values from Query ( Dynamic/AOT ) using X++ in Ax 2009

static void GetRangeValueOfQuery(Args _args)
{

Query query = new Query();
QueryRun queryRun;
QueryBuildDataSource qbd;
Bill_Table vendTable;
QueryBuildRange range;
int ct, i;
;

qbd = query.addDataSource(tablenum(Bill_Table));

queryRun = new QueryRun(query);

queryRun.prompt(); // To Prompt the dialog

ct = queryRun.query().dataSourceTable(tablenum(Bill_Table)).rangeCount();

for (i=1 ; i<=ct; i++)
{
range = queryRun.query().dataSourceTable(tablenum(Bill_Table)).range(i);
info(strfmt(“Range Field – %1, Value – %2”,range.AOTname(),range.value()));
}
range = qbd.addRange(fieldnum(Bill_Table,ItemName));
while (queryRun.next())
{
vendTable = queryRun.get(tablenum(Bill_Table));
info(strfmt(“Item – %1, Name – %2”,vendTable.ItemName, vendTable.CustName));
}

}

range1range

Advertisements

6 comments on “Get the ranges and values from Query ( Dynamic/AOT ) using X++ in Ax 2009

  1. Hi vasanth

    for me it is working fine in Ax 2009 but not in Ax 2012.
    * if u r doing in Ax2009 then you have to add range in Query Prompt Window
    * if u r doing in Ax 2012 you have to add range in Query Prompt Window and the you have to change the code like this for count

    cnt = SysQuery::countTotal(queryRun);

    * after addin the above code im getting count, but Range 1 not found error coming. so if u find any solution please let me know.

    //John

    Like

  2. Hi vasant,

    i got the solution for Ax 2012.Insted of using queryrange.value(i) we have to use query.queryFilter(i);. Just try this and let me the know.

    Code:
    static void Johnkrish_GetRangeValueOfQuery(Args _args)
    {
    Query query;
    QueryRun queryRun;
    QueryBuildDataSource qbd;
    GeneralJournalAccountEntry vendTable;
    QueryBuildRange range;
    QueryFilter qf;
    GeneralJournalAccountEntry generalJournalAccountEntry;
    int cnt, i;
    ;

    query = new query();
    qbd = query.addDataSource(tablenum(GeneralJournalAccountEntry));
    queryRun = new QueryRun(query);
    queryRun.prompt();
    query = queryRun.query();
    cnt=query.queryFilterCount();

    for (i = 1; i <=cnt ; i++)
    {
    qf = query.queryFilter(i);
    info(strFmt("Range Field – %1: Value – %2", qf.field(), qf.value()));
    }

    while (queryRun.next())
    {
    generalJournalAccountEntry = queryRun.get(tablenum(GeneralJournalAccountEntry));
    info(strfmt("PostingType – %1, LederAccount – %2",generalJournalAccountEntry.PostingType, generalJournalAccountEntry.LedgerAccount));
    }
    }

    thanks for asking the question.

    //John

    Like

  3. Pingback: Get the ranges and values from Query ( Dynamic/AOT ) using X++ in Ax 2012 | Learn Dynamic Ax with Johnkrish

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s