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 :
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)
  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi Brian,

    You can add the view as a data source using tableNum(<viewName>).

  • brianmaric Profile Picture
    on at

    Here's my code:

           
           
           
           query = next createBaseCustTransQuery(_party,_statementStartDate,_statementEndDate,_includeReversed);
    
            qbdsCustTrans = query.dataSourceTable(tableNum(CustTrans));
    
            qbdsDimensionAttributeValueSet =  qbdsCustTrans.addDataSource(tableNum(DimensionSetView));
    
            qbdsDimensionAttributeValueSet.addlink(fieldNum(custtrans, DefaultDimension), fieldNum(DimensionSetView, DIMENSIONATTRIBUTEVALUESETRECID));
            
            

    The second line wipes out the SQL in the query.

    What am I missing?

    Also, I can't seem to find the preRunModifyContract.  The only place to do it is in the controller class.

    Thanks

  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    This seems to be a good place to place your code. You could also try doing a CoC on createCustTransQueryForStatementCust method as all the ranges are being set here.

    Could you please explain your statement - "The second line wipes out the SQL in the query."?

  • brianmaric Profile Picture
    on at

    When this line runs:

    query = next createBaseCustTransQuery(_party,_statementStartDate,_statementEndDate,_includeReversed);

    and I check the SQL statement on the query object, it shows the select statement of the CustTable and the CustTrans with the range values for both tables.


    But when this line runs:

    qbdsDimensionAttributeValueSet =  qbdsCustTrans.addDataSource(tableNum(DimensionSetView));

    and I then check the SQL of the query object, there is no CustTable and the CustTrans SQL range values in the query object disappear and is replaced by just the CustTrans Table and the view but without any range values. It is as though my code overwrote the SQL of the returned query object and just replaced it with a new query.

  • brianmaric Profile Picture
    on at

    Here's the first SQL value:

    ThirdImage.png

    Here's the Second:

    SecondImage.png

  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    I tried similar code using DefaultDimensionView and looks like I am getting correct value for variable q.

    pastedimage1647705871331v1.png

  • brianmaric Profile Picture
    on at

    not for me...

    1805.Pic.PNG

    not sure why

  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    Could you please try a full build of your development model, just to make sure there are no build issues?

  • brianmaric Profile Picture
    on at

    I did a full build with 50 warnings but no errors.  I still got the same result:

    4213.Pic2.PNG

  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    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…

Neeraj Kumar – Community Spotlight

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

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

#1
Martin Dráb Profile Picture

Martin Dráb 565 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans