Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Answered

Getting ranges from Query object in X++

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.

  • Martin Dráb Profile Picture
    Martin Dráb 225,588 Super User 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 225,588 Super User 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 225,588 Super User 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.

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,989 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,588 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans