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

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Add a view to a query object in X++

(0) ShareShare
ReportReport
Posted on by

Hi, I'm trying to filter the Customer Statement based on the Financial Dimension.  One simple way is to create a view like tihs:

https://www.axazure.com/en/show-dimensions-in-a-form-without-adding-table-fields

Well, I have this view and I want to use it to filter the records returned on the customer statement.

I'm trying to modify the query in the report classes. 

One simple way would be if I could add the view to the query and then filter on it, but this does seem possible as the query.addDataSource() method wants a tableID.

Can anyone help?

Thanks

I have the same question (0)
  • brianmaric Profile Picture
    on at
    RE: Add a view to a query object in X++

    hmm...so I only need it for my toString() get the right output but not for the code to correctly apply the filter to the report...but I wonder why Gunjan could see the SQL output without needing to call toString().

  • Martin Dráb Profile Picture
    235,961 Most Valuable Professional on at
    RE: Add a view to a query object in X++

    You need to set it if you want to get the right output from toString() and you have several child tables joined to a single parent (e.g. A<-B and A<-C, but not if you have A<-B<-C).

  • brianmaric Profile Picture
    on at
    RE: Add a view to a query object in X++

    That did the trick.

    Do we need to set the fetch mode every time there are multiple tables per level or is this just a matter of display?

    Thank You!

  • Verified answer
    Martin Dráb Profile Picture
    235,961 Most Valuable Professional on at
    RE: Add a view to a query object in X++

    I believe that toString() will display the query string correctly if you set FetchMode of child data source to QueryFetchMode::One2One.

  • Verified answer
    Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Add a view to a query object in X++

    Let us know if you are able to get it working in the environment. Hopefully that answers your original question regarding adding a view to a query object :)

  • brianmaric Profile Picture
    on at
    RE: Add a view to a query object in X++

    The only thing that I know we changed is that we moved all objects from one model into another, I wonder if that had an impact.  I think I'll test it in a different environment if I get the same behavior

  • Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Add a view to a query object in X++

    The code should work fine I think. Not sure why the query is not showing the correct value in the watch window. Did you try running the report to see if the query ranges set for dimensions had any effect on the data?

  • brianmaric Profile Picture
    on at
    RE: Add a view to a query object in X++

    Yeah..same  behavior..

    Pic3.PNG

  • brianmaric Profile Picture
    on at
    RE: Add a view to a query object in X++

    Thanks

    I'm trying that now...

    Interestingly, what did work in the createBaseCustTransQuery method was this..

           

             DimensionProvider.addAttributeRangeToQuery(q,
                                                    qbds.name(),
                                                    identifierStr(DefaultDimension),
                                                    DimensionComponent::DimensionAttribute,
                                                     "Value",
                                                   "AttributeName");
           

  • Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Add a view to a query object in X++

    That's odd.

    Could you try the same code in CoC of createCustTransQueryForStatementCust method and see if you see similar behavior?

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Sohaib Cheema Profile Picture

Sohaib Cheema 756 User Group Leader

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 629 Super User 2025 Season 2

#3
Martin Dráb Profile Picture

Martin Dráb 514 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans