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

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

    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.

  • syed baber Profile Picture
    11,633 on at

    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.

  • Community Member Profile Picture
    on at

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

  • Suggested answer
    Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    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

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

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

    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

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

  • Verified answer
    Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    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

    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.

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