This post is machine-translated. The original post in german language can be found here.

Sort Query by financial dimension

You can use the SysQuery::addOrderByDimensionAttribute() method to sort a query on a financial dimension.

The following example is intended to illustrate this. In this job, all customers are listed, sorted according to the dimension CostCenter.

static void sortByDimension(Args _args)
{
    Query query;
    QueryRun queryRun;
    QueryBuildDataSource qbds;
    CustTable custTable;
    DimensionComponent dimensionComponent;
    DimensionValue dimensionValue;

    #define.CostCenterDimensionName("CostCenter");

    query = new Query();
    qbds = query.addDataSource(tableNum(CustTable));

    SysQuery::addOrderByDimensionAttribute(query,
                                           qbds.name(),
                                           fieldId2name(tableNum(CustTable),
                                                        fieldNum(CustTable, DefaultDimension)),
                                           DimensionComponent::DimensionAttribute,
                                           SortOrder::Ascending,
                                           #CostCenterDimensionName);

    queryRun = new QueryRun(query);
    while(queryRun.next())
    {
        custTable = queryRun.get(tableNum(CustTable));

        // Get dimension value
        dimensionValue =
        (select firstonly DisplayValue from defaultDimensionView
         where defaultDimensionView.Name == #CostCenterDimensionName
            && defaultDimensionView.DefaultDimension == custTable.DefaultDimension).DisplayValue;

        info(strFmt("%1 %2", custTable.AccountNum, dimensionValue));
    }
}
These post applies to following version:
Dynamics AX 2012

Add comment
 
 

 

 
 
 
Posts of the actual month
Januar 2022
MoTuWeThFrSaSu
 12
3456789
10111213141516
17181920212223
24252627282930
31 
 
© 2006-2022 Heinz Schweda | Imprint | Contact | German version | Mobile version
In order to provide you with better service, this site uses cookies. By continuing to browse the site, you are agreeing to our use of cookies.