Friday, 19 July 2019

Axapta 2012 x++ filter the worker lookup

//Override the field data source lookupReference

public Common lookupReference(FormReferenceControl _formReferenceControl)
{
HcmWorkerLookup hcmWorkerLookup;
     SysReferenceTableLookup  tableLookup ;
     Query query = new Query();
     QueryBuildDataSource qbds;
     QueryBuildDataSource qbdsWorkers;



     tableLookup = SysReferenceTableLookup::newParameters(tableNum(HcmWorker), _formReferenceControl);

    qbds = query.addDataSource(tableNum(HcmWorker));
    if (SalesTable.SalesUnitId !='')
    {
         qbdsWorkers = qbds.addDataSource(tableNum(SMMSALESUNITMEMBERS));
         qbdsWorkers.relations(false);
         qbdsWorkers.addLink(fieldNum(HcmWorker,RecId),fieldNum(SMMSALESUNITMEMBERS,SalesPersonWorker));
         qbdsWorkers.addRange(fieldNum(SMMSALESUNITMEMBERS,salesunitid)).value(queryValue(SalesTable.SalesUnitId));

        tableLookup.parmQuery(query);
        tableLookup.addLookupfield(fieldNum(HcmWorker, Person));

        return tableLookup.performFormLookup();
    }
    else
    {
            return HcmWorkerLookup::newOnlyActiveWorkers().lookupWorker(_formReferenceControl);
    }
}

No comments:

Post a Comment