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)

Calling a method on one of a view’s data sources

(1) ShareShare
ReportReport
Posted on by

I have a small dilemma

 

I've created a view OnHandInquiryView (based on query OnHandInquiryQuery)

This view is going to be used as a datasource on a read-only inquiry form, and possibly on a report.

 

When I look at my view’s Metadata --> Datasources, nothing shows up, but they do show up under the Metadata --> OnHandInquiryQuery

The query contains InventTable as a datasource

I have a number of custom display and calculation method on InventTable

One method is called findPackSize, which does all sorts of wonderful things looking at fields on InventTable, unit conversion tables, and other custom tables.

 

I would like to add a display method on my OnHandInquiryView which will call the InventTable’s findPackSize method

How can I reference a view’s datasource (or the datasource in the query that is used to build the view) within a method on that view?

I’ve tried using InventTable, and InventTable_ds, but the method on my view doesn’t like either of those.

 

Rewriting the methods from InventTable onto my OnHandInquiryView is not really desirable, because it would be time consuming, would require me to maintain similar code in two separate methods, and might not work anyway, since I would still need to reference fields from InventTable in my view-level method

 

This is just one example. There are many other methods, on this and other data sources of my view, which I would like to be able to call from a method on my view

 

If anyone has ever done something like this (calling a method on one of a view’s data sources, and/or referencing a field that is not one of the field on the view but is a field in one of the datasources), please let me know.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Brandon Wiese Profile Picture
    17,788 on at

    It is not possible in a view to access methods of underlying data sources.  The reasoning is simple.  Views in the AOT become SQL Server views directly in the database, and SQL Server cannot run X++.  Having said that, it is possible to build some quite powerful logic directly onto those views in the form of computed columns.  There are good examples of this in the AOT.  Check out the views InventTransGrouped, InventTableExpanded, InventSumAggrDeltaView, etc.  There you can see complex usage of the SysComputedColumn class to build calculated fields into SQL Server views.

    It sounds from your description like you probably won't be able to accomplish what your method does using calculated fields.

    There's no reason to be stuck using a view in your case and suffer not being able to use your display methods.  Instead, build a query, which can itself be assigned to the data source of a form, and then allows you to reference the display methods of underlying data sources directly.  And then you can build a view on that query, and use that view in cases where you do not need the display methods.

    Hope this helps.

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

    I have one more suggestion. You clearly can't used InventTable.findPackSize() directly, but you can add a new display method to your view and call the same logic that is used by findPackSize().

  • Community Member Profile Picture
    on at

    That's pretty much what I wound up doing.

    In this case, I was trying to call a custom method on InventTable, and my view contains the ItemId.

    My solution was to write a method on my view which declared an InventTable object. Using the ItemId from my view, I did a find on InventTable, and called the method on InventTable that way. Probably not the most efficient solution, but it works.

    Bill

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

    If you make a database request in your display method, it's quite expensive, therefore you'll get much better performance if you can avoid it. It suggests that your view doesn't contain all necessary fields, therefore consider adding them.

    If you want to have the extra query anyway, make sure that you at least cache the display method.

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