Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

Modify range in AOT query

Posted on by 6,603

Hello and happy Friday.

I have an AOT query I'm calling from within X++ code. On the AOT query, one of the datasource I have a range defined for a specific created date values (I'm currently using greaterThanDate(-90) in the AOT query for testing). At runtime, is it possible to modify the created date range value, say to greaterThanDate(-1), from within X++ before executing the query itself? Hope that was somewhat clear.

Thank you!

*This post is locked for comments

  • Majid Hafeez Profile Picture
    Majid Hafeez 40 on at
    RE: Modify range in AOT query

    Try This IT works fine:

    qbrDate = SysQuery::findOrCreateRange(query.datasourceTable(tableNum(WHSWorkTable)),fieldNum(WHSWorkTable,WorkClosedUTCDateTime));
    qbrDate.value(SysQuery::range(fromDate, todate));

  • Martin Dráb Profile Picture
    Martin Dráb 230,149 Most Valuable Professional on at
    RE: Modify range in AOT query

    if your question isn't related to the topic of this thread ("Modify range in AOT query"), please create a new one.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Modify range in AOT query

    Well, I'm trying to incorporate the union part programmatically to a query in which I have 2 tables already joint.

    but it doesn't seem to work. When I run SQL profiler the query doesnt take into consideration the union piece.

    Do you have any examples for union with complex queries laying around somewhere?. :-)

    Thanks.

  • Martin Dráb Profile Picture
    Martin Dráb 230,149 Most Valuable Professional on at
    RE: Modify range in AOT query

    Everything what you can do with the Query framework can be done even if you create the instance of your Query object from an AOT query.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Modify range in AOT query

    Hello,

    Along the lines of the same question, but totally different :-)
    Can I modified a query who already joins 2 tables and add a 3rd datasource but as a union all?

    Thanks.

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,149 Most Valuable Professional on at
    RE: Modify range in AOT query

    Regarding the new question - yes, you can do whatever you want with such a query.

    For example, find an existing data source (e.g. q.dataSource(tableNumTable(YourTable))), add a range (addRange(fieldNum(YourTable), YourField))) and so on. You'll find many examples both in AX and on internet.

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,149 Most Valuable Professional on at
    RE: Modify range in AOT query

    Not a problem. Find the range by QueryBuildDataSource.findRange() and change its value (QueryBuildRange.value()).

  • bankk Profile Picture
    bankk 6,603 on at
    RE: Modify range in AOT query

    Brandt, thanks for the reply but I'm not sure the question was answered. My dilemma is I have an AOT query, not one that I built in code. The AOT query contains a value in the range node which I would like to change at runtime.

    Better yet, I could phrase the question a little differently. Is it possible to add a range to an AOT query called within X++ code? So this is all I have to access the AOT query from within X++...

       Query q;

       q = new Query(queryStr([AOT query name]));

    Once I have "q", can I modify the query details?

    Thanks!

  • Brandt Fundak Profile Picture
    Brandt Fundak 2,005 on at
    RE: Modify range in AOT query

    I would take a look at the SysQueryRangeUtil class:

    msdn.microsoft.com/.../sysqueryrangeutil.aspx

    Specifically the dayRange method.

    Hope that helps.

    Brandt

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans