FormAutoLookupFactory class and methods in AX 2012 to perform form lookups

Friends,

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

image

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();

    args.name(formStr(HcmWorkerLookup));

    args.caller(this);

 

    args.parmObject(this);

 

    // 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)

    {

        args.lookupRecord(selectedRecord);

    }

 

    // perform form lookup on the caller form control

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

    stringControl.performFormLookup(formRun);

 

    //selectedRecord = formRun.selectRecordModeSelectedRecord();

 

}

There are 4 static methods in FormAutoLookupFactory to explore

image

 

For any reference controls lookups : use

 

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

 

Below is the lookup

image 

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

 

Happy Dax6ng,

sree

Advertisements

One Response to “FormAutoLookupFactory class and methods in AX 2012 to perform form lookups”

  1. Aman Says:

    Very useful. Thanks.


Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

%d bloggers like this: