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, ...
Suggested Answer

How to add a range to a query in a view using x++

(0) ShareShare
ReportReport
Posted on by 18

Hi

How can I modify the query of a view ?

Problem:

I need to expose data to an external app so I have created a view

Inventtable and then join InventItemInventSetup

I only want the record from InventItemInventSetup where invnetdimid is equal InventDim::inventDimIdBlank()

Any hints?

Thanks

I have the same question (0)
  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    You can define such fixed ranges in the query's data source properties, in Ranges node. Just add a range with value "AllBlank". No x++ needed.

    If you want to add ranges in runtime, please share more information about how you expose this view to your external app.

    One way of adding this range in x++ is to use a select statement (select * from myView where myView.InventDimId == 'AllBlank').

  • CU03040925-0 Profile Picture
    18 on at

    Sorry, but AllBlank is not working

    AllBlank was for Ax2012, in D365 you can have Ax#1, Ax#2 Ax#3

    which is why I have to find the 'correct' using the InventDimGlobal::inventDimIdBlank(); function

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    Ok, then you need to define the range during runtime.

    Then it's like:

    InventDimId myBlank = InventDimGlobal::invntDimIdBlank();
    
    select myInventDimView where myInventDimView.InventDimId == myBlank;

  • CU03040925-0 Profile Picture
    18 on at

    As said, Im using the view to expose data so I do not use x++

    I create a DataEntity based on the view and then it is exposed via OData

    and yes, I would love to define the range at runtime, but in the 'code' for the View, I cannot get the query as the view extends 'Common' which is a 'Table'

  • CU03040925-0 Profile Picture
    18 on at

    As said, Im using the view to expose data so I do not use x++

    I create a DataEntity based on the view and then it is exposed via OData

    and yes, I would love to define the range at runtime, but in the 'code' for the View, I cannot get the query as the view extends 'Common' which is a 'Table'

  • nmaenpaa Profile Picture
    101,160 Moderator on at

    Ok so the actual question is: is it possible to filter data entity somehow during runtime, when called via OData? And if it is, how to do it.

  • CU03040925-0 Profile Picture
    18 on at

    No, that is not the question, because in this case, the receiveng app cannot filter which is why the view needs to deliver the excact data

  • nmaenpaa Profile Picture
    101,160 Moderator on at

    I did not say who should do the filtering, it might as well happen inside D365.

  • CU03040925-0 Profile Picture
    18 on at

    yes, and the normal way is to add a range and a value, but in theis case the value is not 'fixed'

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    Anyway, View is actually something that is synced to the database from D365. Same applies to data entities. Since the information about "blank" InventDimId must be fetched using x++ logic, this filter can't be present in the definition of the view or the data entity. Hence it must be filtered somehow in runtime.

    Perhaps you could develop an OData action that finds out the "blank" inventDimId and writes it to a new table (that contains only this one field and always only one record). Then your entity could have exist join relation to that table, and this way the filtering would work. Not the most elegant solution, I know. But it would work.

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 592 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 305 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans