≡ Menu




Custom lookup for Financial Dimension D365 for Finance and Operations (Dynamics Ax 7)

Suppose we have to display all values in “Cost Center” financial dimension in custom lookup. For this post I used unbound field.

So first step is we need we need a text box. So drop a control of type “String” ( “Traditionally it is StringEdit Control”).

Right click on “OnLookup” event and click on “copy event handler method”.

Now add a new class in project, update its same as required. For this post I renamed it as FromControlEventHandler

Between opening closing brackets of class, paste the event code, I copied code in previous step.

[FormControlEventHandler(formControlStr(FrmTestDetail, FormStringControl1), FormControlEventType::Lookup)]
public static void FormStringControl1_OnLookup(FormControl sender, FormControlEventArgs e)
{

}

Later update event method with following code snippet, If you are seasonal Ax consultant or developer you will find this very similar to Ax 2012.

/// [FormControlEventHandler(formControlStr(FrmTestDetail, FormStringControl1), FormControlEventType::Lookup)]
public static void FormStringControl1_OnLookup(FormControl sender, FormControlEventArgs e)
{
Query query = new Query();
QueryBuildDataSource queryBuildDataSource;
QueryBuildRange qbrForAccount;
SysTableLookup sysTableLookup;
// DimType dimType;
DimensionAttribute dimensionAttribute;
// SysTableLookup::newParameters(tableNum(CustTable),sender);
sysTableLookup = SysTableLookup::newParameters(tableNum(OMOperatingUnit),sender,true);
sysTableLookup.parmUseLookupValue(false);
sysTableLookup.addLookupfield(fieldNum(OMOperatingUnit, OMOperatingUnitNumber));
sysTableLookup.addLookupfield(fieldNum(OMOperatingUnit, Name));
queryBuildDataSource = query.addDataSource(tableNum(OMOperatingUnit));
queryBuildDataSource.addSortField(fieldnum(OMOperatingUnit,OMOperatingUnitNumber));
queryBuildDataSource.addRange(fieldNum(OMOperatingUnit, OMOperatingUnitType)).value(int2str(any2int(OMOperatingUnitType::OMCostCenter)));
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();

FormControlCancelableSuperEventArgs ce = e as FormControlCancelableSuperEventArgs;
//cancel super() to prevent error.
ce.CancelSuperCall();

}

There is no need to add different classes for each event. You can copy and write events of different controls in single class.
There is another option on form control event, “Find Event Handler”. On click on it, will leads to event handler reference, I we wrote it. For current post I clicked on “Find Event handler”

results in as

Now let see what will our output. So I pressed Ctrl+F5 to form run without debugging.
Cheers, After pressing Edit Button my unbound custom lookup with Specific financial dimension works fine.

{ 0 comments… add one }

Leave a Comment