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)

How to call table method in view method in Dynamics AX

(1) ShareShare
ReportReport
Posted on by 1,023

Hi every one,

I came across a problem, can any one help me in this regard,

I want to call a table method from a method that is created in a View.Here is the scenario.

I have created a view say "test view", in that i have added a string computed column field named "Field1"Now i want to show the data from another table against the field of this view.lets say there is a filed named  "ItemId" in that view.now i want to created a method in view  that will display the name of the item in the "Field1" field for every record of the view. and for that i am using the below code in the view method.

 InventTable::find("item1").itemName();

but this is not running properly as i am unable to get the current record of the view and also when using the find method the view is giving the errors.

Kindly help me if any one knows the solution.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Jonathan  Halland Profile Picture
    11,310 on at

    Hi you can use "this" keyword

    e.g.

    display str ItemName()

    {

      return InventTable::find(this.itemId).itemName();

    }

  • Muhammad Yasir Profile Picture
    1,023 on at

    Hi Jonathan,

    Thanks for your response.

    The problem is that for computed columns in views, we can not use display methods,we have to create static methods on views in order to return the computed columns and simple methods like you have mentioned earlier are not appearing in the "view method" property of the View fields.

  • Community Member Profile Picture
    on at

    We had similar requirements quite alot and it does not seem like there is an easy solution to this. What we ended up doing was programming the stuff of the display method into the computed column but the more complex the display method gets the harder it is (or even impossible).

    I would be very interested in a better solution as well.

    It's clear that the view can't process a record display method at non-runtime, but how do you efficiently program requirements like 'Customer X wants to filter by product name.'?

  • Douglas Noel Profile Picture
    3,905 on at

    Hi Jens,

    you're absolutely right, even implementing such "obviously simple" itemname() display x++ methods as a native T-SQL statement within a 'computed colum', which works exactly like the display method,  seems to be sheer madness and extremely dependent on the 'digit'

    behind the letter "R" of 2012,

    If you moreover - let us take this "simple example"-  want to have the language dependency within it, you have to "multiply" the records, and filter for the current LanguageID on the appropriate view field.

    Even not regarding the language (and maybe always use a defined fixed language) it seems to be a better way to use a additional HelperTable (withinAX) for that, which is updated in regular intervals or on demand (new inventtable ...)

    But having this helper table it seems to be not neccessary to have a computed column on the view, you can (important) outer join the non neccessary up-to-date helper table to your base table from within view definition (!!!!!! must use query based view for that), and maybe creating a additional 'computed column' on that view which de-NULLs the outerjoined field in all cases to an empty string.

    regards

    Douglas

  • Community Member Profile Picture
    on at

    Thanks for your Input. A helper table would work for sure, but as you said it's all together not that great of a solution because there has to be a batch job that updates the table and then you have duplicate data all over the place.

    While for item name it might not be that crucial to be up to date there are other requirements where it might not be possible at all to wait for a batch job to run.

    This really is a point where Microsoft should put in some thought. It's really common that people want to filter just everything and especially the product name.

  • Douglas Noel Profile Picture
    3,905 on at

    Hi ,

    you are right. Using such helper tables can only be used in situations where the frequency of changes (for the wanted data) is 'low'.  This will work for the product name but not for other data.

    So I'm with you.

    And moreover: The usage of such helper tables is Ax standard: Look at all the SSRS reports which use some preprocessed helper tables for things which couldn't be archived in another way (if you need such things as filtering etc.)

    So you have some kind of helper tables already here (and they get filled each time) - yes I know they are normally temporary ones,  but using "real" data fields here, filling it from within preProcess from within Ax X++ logic,  is a similar problem.

    regards

    Douglas

  • Jonathan  Halland Profile Picture
    11,310 on at

    Hi Muhammad, I'm still not entirely understanding your question. Do you want to use a display (or other) method from one of the source tables of the view to display as a calculated field on the view?

  • Community Member Profile Picture
    on at

    Hi Jonathan,

    I am facing similar problem, I want to add a computed field in a view and bind it with itemName data method of InventTable. I am not understanding how to write logic in view for itemName?

    Thanks,

    Samia

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