Tuesday, March 5, 2013

AX 2012 Unbound RecId Lookup

Just a simple tip here that Google didn't turn up a quick answer on.

In 2012, many tables use the RecId field as the Primary Key.  The 'human readable' value is then defined using an Index with the Alternate key property set to Yes.

When creating a lookup (dropdown) in this case, you probably need to get the RecId, but want the user to see the Alternate key displayed.

Joris has a great post on how this works when your lookup is on a table that has a foreign key relation to the lookup table. (http://daxmusings.codecrib.com/2011/07/ax-2012-recids-and-unitofwork-foreign.html)

In my case, I was looking to create a simple dialog form with an unbound field (DataSource and DataField properties not set).

My first attempt was to create an Int64Edit control and set the ExtendedDataType (EDT) property.
Of course, this results in this:
Overriding the lookup method can help with the values shown when the dropdown is displayed, but it doesn't fix that the RecId is shown in the field.

The answer is a new type of control called Reference Group.  (add it to your form just like any other type: right click, New Control, ReferenceGroup)
At first, the Reference Group will be empty, but when you set the ExtendedDataType property, a field is automatically added to the group.  Below I've renamed the reference group and set the EDT property.
And the result is:
Nice!

The underlying RecId can be referenced by setting AutoDeclaration to Yes and using value() method on the reference group control.  In the example above, that would be ctrlPlanPeriodRefGroup.value().

4 comments:

  1. It was in msdn already :)
    http://msdn.microsoft.com/en-us/library/gg845085.aspx

    ReplyDelete
    Replies
    1. Thanks for the link. That's just what I was looking for the other day! Maybe my post will help someone else find it more quickly.

      Delete
    2. I couldn't find an answer for how to find the recid for a reference group on msdn, but found it here in value().
      Thanks!

      Delete
  2. This post is very useful. Thank you!

    ReplyDelete