Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Getting ranges from Query object in X++

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi all

I'm having trouble getting all the ranges from a Query object.

This is what i have in the screen:

ni4vRFj_5B00_1_5D00_.png

This is what i have in code:

private str CreateQueryFiltersLine(Query _query)
{
    QueryBuildDataSource    qbd, joinedQbd;
    QueryBuildRange         queryRange;
    int                     dsCount, i, rangeCount, y;
    str                     result;        
    str                     blob;

    dsCount = _query.dataSourceCount();

    for (i = 1 ; i <= dsCount; i++)
    {
        qbd = _query.dataSourceNo(i);
        rangeCount = qbd.rangeCount();
                        
        for (y = 1 ; y <= rangeCount; y++)
        {
            queryRange = qbd.range(y);
            result += strFmt('%1: %2\n', queryRange.fieldName(), queryRange.value());
        }                
        
        if (qbd.joined())
        {
            blob = BinData::dataToString(qbd.joinedDataSources());
        }
    }

    return result;
}

Looping gives me these objects in the debugger.

First datasource:

ds1.png

Second datasource:

7522.ds2.png

Looping over the datasets gives me only 1 range for the second data source

The problem is that i'm only getting the first range (the billable line one) from the screen. Not the second. 

I believe this is due to the fact that the second filter is on a joined data source (of the first datasource).

However, im not sure how to cast the blob im getting from the qbd.joinedDataSources() call.

Any ideas would be appreciated.

*This post is locked for comments

  • Martin Dráb Profile Picture
    Martin Dráb 230,458 Most Valuable Professional on at
    RE: Getting ranges from Query object in X++

    It's a root if it doesn't have any parent data source, which you should be able to get from parentDataSource() method.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Getting ranges from Query object in X++

    Final question: is there a way to recognize root datasources?

    I'm getting the following datasources:

    • InventTransOrigin_1
    • InventTrans_1
    • InventTransOrigin_1_1

    Im guessing AX is recognizing the joins as subdatasources?

  • Martin Dráb Profile Picture
    Martin Dráb 230,458 Most Valuable Professional on at
    RE: Getting ranges from Query object in X++

    As far I know, it depends on the number of root datasources. If you have just a single root DS and all other datasources are joined to it, you'll run it once. But if you had more root datasources, such as two DS unrelated to each other, getting filters for only one of them wouldn't be sufficient.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Getting ranges from Query object in X++

    Martin you made my day: have a badge ;-)

    I'm getting double values now:

    InventTransId: BE01LOT000013301
    ADUBillableLineRecId: ""
    InventTransId: BE01LOT000013301
    InventTransId: BE01LOT000013301
    

     

    Seems like i only need to enumerate the filters/ranges of the first/top datasource or am i wrong?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Getting ranges from Query object in X++ (AX 2012 R3)

    Hi Martin

    Is there a difference between user's input and a range on the query in the AOT?

    Might that be the problem? Anyhow, let me try :-)

    *EDIT*

    The second range was indeed a user input filter.. :-)

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,458 Most Valuable Professional on at
    RE: Getting ranges from Query object in X++ (AX 2012 R3)

    Your own images proves that you get both datasources, therefore it's not clear to me what other datasource would you like to get by calling joinedDataSources().

    I suspect that it's a filter, not a range, therefore you should get it by Query.queryFilter() method. Give it a try.

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,711 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans