AX 2012 Navigation Properties

It’s been a while since I’ve posted, but here’s a small little post about what I think is a cool feature in Ax 2012!

In AX2009, when you have a table that has a relation to another table and you want to use it in code, you have to provide a method that performs a select on the other table and returned the related record. ( fe : SalesTable.SalesLine() ) Well this is something cool in AX2012. Here’s how you can do it now.

On the main table you have the relationship. There you can use a new property called CreateNavigationPropertyMethods and set it to Yes.

Once you have done this, there will be a method on you table that returns the related record.

 

Warning: count(): Parameter must be an array or an object that implements Countable in /customers/5/2/1/ksaelen.be/httpd.www/wordpresses/dynamicsaxblog/wp-includes/class-wp-comment-query.php on line 399

4 thoughts on “AX 2012 Navigation Properties

  1. Tried this; simple lookup on RTM Demo data.
    put in a job the following code:
    CustTable ct = CustTable::find(‘1103’);
    ContactPerson cp = ct.ContactPerson();
    info(cp.Title);
    contact person object is empty. Wondering how a child set of data is supposed to work with this attribute change.
    Any insight to this?

  2. Using the automatically created navigation property method for simply record reads is actually quite **dangerous**.

    This property and created method is intended for use with UnitOfWork or something similar. Multiple calls to this method may retrieve the exact same buffer (not just the same record from the database). You can then have some subtle problems where one class modifies this buffer and another class expects to read what is actually in the database but in reality gets the buffer that was modified in the first class.

  3. We recently encounter a weird problem.

    We have a RefRecId field on table A (tableA.B). When we use navigation property method to fetch related table B (tableA.B()), then the fetched record does not have the same RecId as the RefRecId on table A…
    For some reason, the navigation property methods seem to have gone corrupt in some way :S
    Anyone ever encountered this and knows a solution to this problem?

    Thanks,
    Wouter

  4. Is it possible there is a second field with a relation to the same table? Then the navigation method might use that field by accident

Leave a Comment Yourself

Your email address will not be published. Required fields are marked *