Creating a lookup field for a financial dimension in Dynamics 365

The information in this post is based on Dynamics  365FO, but most of it will also work for Dynamics AX 2012 (see below).

I was recently tasked with creating a new field in which it should be possible to specify a single financial dimension, in this case Product. Of course, the new field should also be able to lookup the the valid values of this dimension.

This is a bit more complicated than a regular lookup in a table, but if you know how, it’s actually not too bad.

Fortunately, the standard application provides a convenient lookup form (DimensionLookup) that can be used for the purpose, if you just tell it which dimension attribute to lookup.

First, you need to create the form field itself. This can be based on a table field or an edit method, doesn’t matter for the lookup itself, but in one way or another it must use the DimensionValue extended data type.

You then need to create an OnLookup event handler for the field (to create an event handler, right-click the OnLookup event for the field, then choose “Copy event handler method”. You can then paste an empty event handler method into a class and edit it from there)

(Notice: Most of this will work for Dynamics AX 2012 as well, but instead of creating an event handler, you can override the form field’s lookup method)

The event handler must look like this (replace form name and field name as necessary):

    FormControlEventHandler(formControlStr( MyForm,
public static void MyProductDimField_OnLookup( FormControl _sender,
                                               FormControlEventArgs _e)
    FormStringControl   control;
    Args                args;
    FormRun             formRun;
    DimensionAttribute  dimAttribute;

    dimAttribute    =   DimensionAttribute::findByName('Product');

    args            =   new Args();

    formRun         =   classFactory.formRunClass(args);

    control         =   _sender as FormStringControl;