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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Getting ranges from Query object in X++

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    237,803 Most Valuable Professional on at

    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.

  • Community Member Profile Picture
    on at

    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.. :-)

  • Community Member Profile Picture
    on at

    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?

  • Martin Dráb Profile Picture
    237,803 Most Valuable Professional on at

    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
    on at

    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
    237,803 Most Valuable Professional on at

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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans