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)

Link between Grid and it's DataSource table, I want to intervene and change what/when is saved in the table and what/when is data retrieved from table.

(0) ShareShare
ReportReport
Posted on by 70

So, I'm gonna try and explain myself, as the title seems a little bit confusing. I have a form and a grid on this form. When I make changes to this grid, the changes are automatically applied to the datasource table. I want to write my own insert() to save data in the datasource table and I want to write my own select() to retrieve data from the table. Where can I do that? I tried to write it in enter() method of the grid, also in executequery() method of the datasource but I couldn't get through it, because I couldn't control when the data was saved or retrieved. Sorry if I didn't make myself clear and thank you in advance to whoever replies this post. 

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Joris dG Profile Picture
    17,775 on at

    The idea with bound controls is of course that it applies your changes automatically. It almost sounds like you're looking for unbound controls and then manipulate the table yourself.

    You may be looking at the wrong approach for your problem. Not knowing what you are trying to do exactly, consider a few of these options:

    1. Create a temp table which you use for binding on the form/grid. Then add a process somewhere that takes the entries in the temp table and do exactly what you want to the actual tables you need to manipulate.

    2. Use unbound controls. You can't really do this on a grid but you could use the "table" control but that is a lot of work since you have to manage all the rows and columns manually. That table  "grid" is not bound to a datasource at all, allowing you to do anything you want.

    3. Try a WPF control. You could do a WPF grid and trigger some X++ code on certain events on the grid, at which point you can manipulate the actual table.

    4. You could use edit methods. They allow you to have users enter anything, but you have to handle what you do with that data. Reversely, you can return anything you want from the method to display on your grid. Keep in mind these methods are NOT very efficient (the way the UI works) and can be a serious performance issue. If you have a lot of them, consider a temp table approach.

    As far as the events you're looking for, you can use write() which is the insert/update on the datasource. You can also use active when a record is selected. But again, since your grid controls are bound, I'm thinking you're going about this the wrong way. Inside the write() you can access the orig() method which returns the original data as it was retrieved from the database prior to the user manipulating it.

    Hope this helps. I'm curious to hear your actual requirement, we may have some better ideas for approaches when we know WHY you are trying to do this.

  • Someone Else Profile Picture
    70 on at

    Thank you for your comment. I'm glad you're curious. As you might've guessed, I'm no expert, it's been exactly a month since I saw AX for the first time. Anyway, I'm gonna tell you what I'm trying to do.

    I have a list of people and I want to create wishlists of items for each of them. These people are in GridHeader, the items are in GridLineView. When I select a person in GridHeader, I change the tab and see his items in GridLineView. I can add/delete items in GridLineView. I'm using one table to save data and 2 tables to retrieve information about people and items. I want to save one field ('Name') of GridHeader along with 3 fields ('ItemId', 'itemName', 'Quantity') of GridLineView in the table. There are these fields in this table: 'Name', 'ItemId', 'itemName', 'Quantity'. So, I select a record in GridHeader, change tab to the GridLineView, create a few items and save the specs of this item along with the name of the person. Each record regarding this person will have his name in the field 'Name'. Later, when I'll want to see which things are in a person's wishlist, I'm gonna need to retrieve items from that table by filtering with a person.  I'm gonna select only those records which have a particular person in the field 'Name'.

    So, that's it, even if you won't reply again, I'm still grateful. I'm gonna continue to work on this subject on Monday and I think you're post will help me big time, thanks again.

  • Suggested answer
    Joris dG Profile Picture
    17,775 on at

    This is a lot easier scenario than what I expected :-)

    As you may or may not know, data types in AX have metadata regarding the related table that stores the data. For one, this results in automatic lookup dropdowns (for example your person and your item) if you use the right data type for the fields on your new table. Secondly, that metadata gets copied to your table as relations, which will help in automatic linking/joining of tables and datasources.

    Is there a specific reason you're storing the name of the item? Or do you just want to display it?

    Something else to look into is the primary key versus alternate key thing in AX. By default, records have RecIds as their primary keys. Those are numbers, but even though you store those (like say, for a person from the global address book) you can actually have the UI show and let users enter the actual name. I've blogged about this feature (which is new since AX 2012) here: daxmusings.codecrib.com/.../ax-2012-recids-and-unitofwork-foreign.html

    ItemId unfortunately uses the ID as the primary key, so you can't do the replacement easily. However, on your form you can add something called a "reference datasource" so that you can always show the item's name along with the ID (basically the reference DS adds a join).

    Lastly, if you are not going to store the actual header (since it's just the person), you may consider a pattern in AX where you have just the grid for your "lines". Then at the top you can add an unbound control, give it the person data type (so that you get a dropdown), and you can act on the "modified" of that unbound control to change the queryrun filter on your table's datasource. Also remember that a grid automatically has the grid filter (CTRL+G) but that doesn't have lookups.

    If you actually had two tables, they would easily just be joined and all filtering would work automagically.

    A good book for you may be the developer's cookbook for AX. It's not a huge big book but some of this filtering and other stuff is explained in there i think. Make sure you get the 2012 version.

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