X++ Look ups - Existing form as a field lookup in another form

Option 1:
A new field is added and that should show an already created form as its lookup.

Create a new form with datasources and design.
In design properties give window type = content page, style - lookup


In the main form to get existing form as lookup, create a new form control and override lookup method as below.

public void lookup()
{

   SysTableLookup          sysTableLookup ;

    Query                   query           = new Query();
    QueryBuildDataSource    queryBuildDataSource;
    QueryBuildRange         queryBuildRange;
    DimensionValue  value;
    Args args;
    FormRun formRun;
    ;
    args = new Args();
    args.name("HcmWorkerEligibleLookup");
    args.record(PurchReqTable);
    args.parmEnum(NoYes::Yes); //
    args.caller(this); //
    formRun = classFactory.formRunClass(args);
    formRun.init();
    formRun.run();
    formRun.detach();
    this.performFormLookup(formRun);
}


In the main form init method, add below code.

public void init()
{
    super();
this.selectmode(formname_field from datasource to be shown in the lookup

eg: this.selectMode(HcmWorkerEligibleTable_EmplName);

}


Option 2:

For the new field, override lookup method as follows.

public void lookup()
{
    //super();
    Query query = new Query();
    QueryBuildDataSource queryBuildDataSource;
    QueryBuildRange queryBuildRange;

    SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(custTable),this);

    sysTableLookup.addLookupfield(fieldNum(CustTable, AccountNum));
    //sysTableLookup.addLookupfield(fieldNum(CustTable, AccountStatement));

    queryBuildDataSource = query.addDataSource(tableNum(CustTable));

    queryBuildRange = queryBuildDataSource.addRange(fieldNum(CustTable, AccountNum));
    queryBuildRange.value('');
    sysTableLookup.parmquery(query);

    sysTableLookup.performFormLookup();
}

Comments

Popular posts from this blog

AX 2012 DEVOPS Build, Release setup and configuration

AX 2012 Build process using AZURE DEVOPS

What is Microsoft Power Platform?