web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How to apply Dimension Range on execute query

(1) ShareShare
ReportReport
Posted on by 1,909

Dears,

I have lookup on Sting Ctrl which returns only specific dimension value. Now If I select Dimension value from lookup I need to filter the grid based on selected dimension value from lookup. Could you please let me know any example on executeQuery() to build logic with specific Dimension Range.

Thanks

Faqru

*This post is locked for comments

  • Verified answer
    Mea_ Profile Picture
    60,286 on at

    Hi Faqru Shaik,

    You can use DimensionProvider class for that, check this blog post axforce.wordpress.com/.../using-the-class-dimensionprovider-to-filter-a-query-with-multiple-financial-dimensions-criteria for example

  • Faqruddin Profile Picture
    1,909 on at

    Thanks ievgen. Lets say SalesTable have FinancialDimension "CostCenter. And I need filter  on "CostCenter" value only on my customized form. Any Ideas ?

  • Mea_ Profile Picture
    60,286 on at

    what do you mean "any ideas" I gave you a blog post to follow, what's wrong with it?

  • Verified answer
    Hossein.K Profile Picture
    6,650 on at

    Hi Faqru,

    Try this code:

    static void addDimensionRange(Args _args)
    
    {
    
        Query                   query = new Query();
    
        QueryRun                queryRun;
    
        QueryBuildDataSource    qbds;
    
        DimensionProvider       dimensionProvider = new DimensionProvider();
    
        GeneralJournalAccountEntry  accEntry;
    
        DimensionAttribute      dimAttr;
    
        Name    dimAttrNameEmpl, dimAttrNameCostCenter;
    
        int i;
    
        ;
    
     
    
        select firstOnly dimAttr where dimAttr.BackingEntityType == tableNum(DimAttributeHcmWorker);
    
        dimAttrNameEmpl = dimAttr.Name;
    
       
    
        select firstOnly dimAttr where dimAttr.BackingEntityType == tableNum(DimAttributeOMCostCenter);
    
        dimAttrNameCostCenter = dimAttr.Name;
    
       
    
        qbds = query.addDataSource(tableNum(GeneralJournalAccountEntry));
    
     
    
        dimensionProvider.addAttributeRangeToQuery(query, qbds.name(), fieldStr(GeneralJournalAccountEntry, LedgerDimension), DimensionComponent::DimensionAttribute, SysQuery::valueNotEmptyString(), dimAttrNameEmpl, true);
    
        dimensionProvider.addAttributeRangeToQuery(query, qbds.name(), fieldStr(GeneralJournalAccountEntry, LedgerDimension), DimensionComponent::DimensionAttribute, SysQuery::valueNotEmptyString(), dimAttrNameCostCenter, true);
    
     
    
        queryRun = new QueryRun(query);
    
        queryRun.prompt();
    
       
    
        while(queryRun.next())
    
        {
    
            accEntry = queryRun.get(tableNum(GeneralJournalAccountEntry));
    
            info(strFmt("%1 <–> %2", DimensionAttributeValueCombination::find(accEntry.LedgerDimension).DisplayValue, accEntry.AccountingCurrencyAmount));
    
        }
    
    }


  • Verified answer
    Heinz Schweda Profile Picture
    1,367 on at

    Hi,

    maybe the following function is, what you are searching for?

    public void init()
    {
        super();
        
        SysQuery::addDimensionAttributeRange(salesTable_ds.query(),
                            salesTable_ds.name(),
                            fieldStr(Salestable, DefaultDimension),
                            DimensionComponent::DimensionAttribute,
                            '1001',
                            'CostCenter');    
    }


    Kind regards,

    Heinz

  • Faqruddin Profile Picture
    1,909 on at

    Thanks Heinz. This what I'm exactly looking for. But How I can pass   my StringCtlr to above code ? So I can filter the grid.

  • Verified answer
    Heinz Schweda Profile Picture
    1,367 on at

    You could set the property AutoDeclaration of your control to YES and use NameOfYourControl.valueStr()

  • Faqruddin Profile Picture
    1,909 on at

    Thanks Heinz. It works. But once I clear the filter box the grid is showing with same values again.

  • Verified answer
    Heinz Schweda Profile Picture
    1,367 on at

    In that case you can use SysQuery::clearDimensionRangesFromQuery()

  • Faqruddin Profile Picture
    1,909 on at

    Thanks. Still it same by using SysQuery::clearDimensionRangesFromQuery(). Is SysQuery::clearDimensionRangesFromQuery() applicable to clear single dimension field range if I use QueryBuildRange and SysQuery::findOrCreateRange ? I just pass standard query value. But its not clearing the range.  

    void executeQuery()
    {
     Query q = new Query(); 
     QueryBuildDataSource qbds, 
    
     qbds = q.addDataSource(tableNum(SalesTable));
    
      sysQuery::clearDimensionRangesFromQuery(q);
    
        SysQuery::addDimensionAttributeRange(q  ,
                            qbds.name(),
                            'DefaultDimension',
                            DimensionComponent::DimensionAttribute,
                             RootControl.valueStr() ,
                            'root');
    super();
    }


Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Prashant Singh Profile Picture

Prashant Singh 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans