FormAutoLookupFactory class and methods in AX 2012 to perform form lookups


FormAutoLookupFactory class has been newly introduced in AX 2012 which will help for form lookups on controls [strings, integers], Reference controls etc. by returning formRun class object

Create a new form as shown below with a new string edit control


Override the lookup method of the String Edit and add the below code

public void lookup()


HcmWorker               selectedRecord;

Args                    args;

FormRun                 formRun;

Form                    workerLookupForm = new Form(formStr(HcmWorkerLookup));

FormControl             control = this;

FormStringControl       stringControl       = control as FormStringControl;


args = new Args();;





// position the lookup to highlight the current record

// a string control supposed to contain a personnel number value

selectedRecord = HcmWorker::findByPersonnelNumber(stringControl.text());


if (selectedRecord.RecId != 0)





// perform form lookup on the caller form control

formRun = FormAutoLookupFactory::buildLookupFromCustomForm(stringControl, workerLookupForm , AbsoluteFieldBinding::construct(fieldStr(HcmWorker, PersonnelNumber), tableStr(HcmWorker)), args);



//selectedRecord = formRun.selectRecordModeSelectedRecord();



There are 4 static methods in FormAutoLookupFactory to explore


For any reference controls lookups : use


formRun = FormAutoLookupFactory::buildReferenceLookupFromCustomForm(referenceControl, workerLookupForm, args);


Below is the lookup


Also, There are 2 new methods added in AX 2012 to formrun class as well selectRecordModeSelectedRecord() and selectrecordMode()  that will help to get the selected records.

Please note: This is just a quick example and you need to customize it based on your requirement from the calling control




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s