Skip to main content

Notifications

Dynamics 365 Community / Forums / Finance forum / How to add a range to ...
Finance forum
Suggested answer

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

Posted on by 60

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

  • steen.rabol Profile Picture
    steen.rabol 95 on at
    RE: How to add a range to a query in a view using x++

    Ok, that's fine I did not know that the query is only used to generate the view

    I'll do the debugging tomorrow and get back with the details

  • Martin Dráb Profile Picture
    Martin Dráb 227,996 Super User 2024 Season 2 on at
    RE: How to add a range to a query in a view using x++

    All right, let's answer it: The query is used only on synchronization to generate T-SQL code defining the view in database. At runtime, you get data returned from the view in database; the original query isn't used at all and therefore any attempt to do anything with it is futile.

    If you're now willing to look for something that can be done, could you give me a favour and debug the code to see where "Ax1" value is coming from?

    When you know the pattern, such as that all IDs you're interested in starts with "Ax", filtering the data isn't difficult.

  • rabol Profile Picture
    rabol 60 on at
    RE: How to add a range to a query in a view using x++

    and the question is not wether the default dimid is 'AllBlank' or not, the question is about how to access the query of a view by code :)

  • rabol Profile Picture
    rabol 60 on at
    RE: How to add a range to a query in a view using x++

    Hi

    I completly agree - according to the code it looks like it would be 'AllBlank'

    We are woking on a upgrade from AX4 to D365

    in SQL:

    select * from INVENTDIM where inventdim.INVENTDIMID like 'a%' and DATAAREAID = 'dis'

    Gives me 4 rows (i just show invnetdimid here)

    Ax#1
    Ax#2
    Ax#3
    Ax1

    InventDimGlobal::inventDimIdBlank()  return Ax1

    So.... I'm as sure as I can be

  • Martin Dráb Profile Picture
    Martin Dráb 227,996 Super User 2024 Season 2 on at
    RE: How to add a range to a query in a view using x++

    Are you sure that blank dimensions IDs can be something like Ax#1?

    When I'm looking into InventDim::findOrCreateBlank() (which is what actually does the job, InventDimGlobal::inventDimIdBlank() only adds caching), I see that the dimension ID is either 'AllBlank' or 'AllBlank2'.

    static public InventDim findOrCreateBlank()
    {
    	#define.blank('AllBlank')
    	InventDim   inventDim;
    	InventDim   inventDimAllBlank;
    	InventDimId inventDimIdBlank = #blank;
    	Counter     logCount;
    
    	inventDim = InventDim::find(inventDimIdBlank);
    	if (inventDim.RecId && InventDim::isInventDimEqual(inventDim, inventDimAllBlank))
    	{
    		return inventDim;
    	}
    
    	if (inventDim.RecId)
    	{
    		inventDimIdBlank  = '2';
    	}
    
    	...
    }

    Am I missing something?

    For the record, my application version is 1.0.0.6.

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,148 on at
    RE: How to add a range to a query in a view using x++

    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.

  • rabol Profile Picture
    rabol 60 on at
    RE: How to add a range to a query in a view using x++

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

  • nmaenpaa Profile Picture
    nmaenpaa 101,148 on at
    RE: How to add a range to a query in a view using x++

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

  • rabol Profile Picture
    rabol 60 on at
    RE: How to add a range to a query in a view using x++

    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
    nmaenpaa 101,148 on at
    RE: How to add a range to a query in a view using x++

    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.

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Dynamics 365 Community Newsletter - August 2024

Catch up on the latest D365 Community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,186 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 227,996 Super User 2024 Season 2

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans