Tuesday, June 28, 2011

Cycle through datasources and ranges to find values

Here is some basic code to cycle through a datasource in AX 2009 X++ and then loop through all of the data sources and their ranges and present some info to the users. Its nice for analyzing queries if something is not acting right. 

If you use this code, please leave me a comment and say thank you.  Its nice just to have someone say hi or thanks for using code like this.  If you don't use it and it helps you out, feel free to say so to.  We're all friends here :-)

// START CODE
// 2009 DAX DUDE

    int test1;
    int test2;
    int dsCount;
    int dsPlace;
    QueryBuildRange qbrTEST;
    QueryBuildDatasource qbdsTest;

    dsCount= queryRun.query().dataSourceCount();
    for (dsPlace= 1; dsPlace<= dsCount; dsPlace++)
    {
        qbdsTest = queryRun.query().dataSourceNo(dsPlace);

        test1 = qbdsTest.rangeCount();

        for (test2 = 1; test2 <= test1; test2++)
        {
            qbrTEST = qbdsTest.range(test2);

            info (strFmt("Range Field %1, Value %2", qbrTEST.AOTName(), qbrTEST.value()));
        }
    }
// END CODE

1 comment: