Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)
Answered

How to access whole query of the form?

(0) ShareShare
ReportReport
Posted on by

I have a form. It has query property set to myQuery. I know how to access datasources that query is composed from. I know how to access the sub-queries from that datasources. But I was to access whole query (queryRun) object that is associated with form.

How can I do it?

I was trying to use things like element.getPrimaryDS().query(); etc. but I do not thing that returns me whole myQuery object.

*This post is locked for comments

  • Community Member Profile Picture
    on at
    RE: How to access whole query of the form?

    It looks like the problem was in Relations proper ty which does not exist on form datasource and on the AOT query it is set to 'No' by default so my query way ignoring the relations from tables while form was not ignoring them. If this will show up right I will mark your last sentence as an answer.

  • Verified answer
    Martin Dráb Profile Picture
    231,927 Most Valuable Professional on at
    RE: How to access whole query of the form?

    I think the most likely explanation is that your AOT query isn't the same as the query in your first form. Ensure yourself that the data sources are joined correctly. If you don't see any problem, please show us the query string (TableA_DS.query().dataSource(1).toString()).

    You should always check the query string when debugging queries.

  • Community Member Profile Picture
    on at
    RE: How to access whole query of the form?

    Yes I say " if I use the same code for filtering a data source, you get different behavior depending on whether the data source has been created directly from a table or from a table in from an AOT query"

    When I add range on B I will see data on grid (where A is) filtered on Form1 and it ignores range on Form2. The range is added in methodn on form by  TableB_DS.query().dataSourceName('TableB').addRange. Then TableA_DS.executeQuery(); (I try various cases with TableB_DS.executeQuerx() etc. )

  • Martin Dráb Profile Picture
    231,927 Most Valuable Professional on at
    RE: How to access whole query of the form?

    Do you say that if you use the same code for filtering a data source, you get different behaviour depending on whether the data source has been created directly from a table or from a table in from an AOT query?

    Or do you set the range in the AOT query in the latter case?

  • Community Member Profile Picture
    on at
    RE: How to access whole query of the form?

    I have Form1 it has datasources, grid etc. (No query included.)

    I created query - query1 with same structured datasources as the Form1 has.

    I create Form2 and put query1 to the datasource query property. I can access datasources from query like TableA_DS same as I would do it on Form1 but the ranges act differently (Form1 vs Form2).  

  • Suggested answer
    Martin Dráb Profile Picture
    231,927 Most Valuable Professional on at
    RE: How to access whole query of the form?

    You said it works if "created by datasources" but not if "recreated in query", but I'm not sure what it means. Are you saying that if you change your AOT query, you don't see the change in your form? Then try to re-add the query to your form.

  • Community Member Profile Picture
    on at
    RE: How to access whole query of the form?

    The query have structure

    -A

    --B (inner join 1:1)

    --C (outer join 1:1)

    -D

    -E

    When it is created by datasources I can run B_DS.query().dataSourceName('B').addRange(fieldNum(B, BField)).value('some value');

    A.executeQuery();

    and in a grid where A is datasource I can see only rows with link to B with right value.

    If I recreate it in query and use query then this does not work and after B range and A execute nothing is changed in grid.

    (I know the best practice would be add ranges to derived query and swithing queries but for test purposes I would like to do it in code.)

  • syed baber Profile Picture
    11,633 on at
    RE: How to access whole query of the form?

    Hi Vaclav,

    You need to loop through the form's datasource. Check the following blog post:

    https://community.dynamics.com/ax/b/axaptavsme/archive/2012/11/06/finding-all-data-sources-in-a-form-through-job.aspx

    Please verify and let me know if you need further help.

    Thanks,

    Baber.

  • Suggested answer
    Martin Dráb Profile Picture
    231,927 Most Valuable Professional on at
    RE: How to access whole query of the form?

    Take the root data source and call its query() method, e.g. myTable_ds.query().

    If it doesn't return what you expect, please explain the problem to us.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,265 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,927 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans