Search code examples
axaptalookupdynamics-ax-2012x++

How to get RecId selected from lookup method?


I want to get the RecId selected from lookup method?

In lookup method in StringEditLookup_ZipCode

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

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

sysTableLookup.addLookupField(fieldNum(LogisticsAddressZipCode, ZipCode));
sysTableLookup.addLookupField(fieldNum(LogisticsAddressZipCode, City));

sysTableLookup.addSelectionField(fieldNum(LogisticsAddressZipCode, RecId));

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

sysTableLookup.parmQuery(query);

sysTableLookup.performFormLookup();
//super();
}

In modified method I would want to get ad read and use the RecId taken.

I want to populate the StringEditLookup_ZipCode with the ZipCode value.

It's possible to take a RecID ? The LogisticsAddressZipCode Table is's not indexed by ZipCode for this I need to take the RecID.

There is a way to save in a global variable or somehow recid selected in the lookup method or another point?

Thanks all,

enjoy!


Solution

  • As far as I know this cannot be done with the SysTableLookup Framework. Basically you want your lookup to return two values, the ZipCode and the RecId. But the framework can only return one value.

    So instead of the framework you will need to implement your own lookup by creating a new lookup form. From this form you can then retrieve the selected record in the lookup method. Here is some code to give you an idea how the lookup method could look like:

    public void lookup()
    {
        FormRun lookupFormRun;
        Args args;
        LogisticsAddressZipCode myLookupZipCode;
    
        args = new Args();
        args.name(formStr(MyNewLookupForm));
        lookupFormRun = classFactory.formRunClass(args);
        lookupFormRun.init();
        this.performFormLookup(lookupFormRun);
        lookupFormRun.wait();
        if (lookupFormRun.closedOk())
        {
            myLookupZipCode= formRun.docCursor();
        }
    }
    

    From there you can save the RecId of myLookupZipCode to a class variable and then later use it in the modified method.

    Also take a look at Lookup form returning more than one value for additional Information.