How to create Lookup Worker Filtered by Legal Entity[AX2012]

时间:2023-12-11 20:24:32

1. Add a new method in hcmWorker table, and add this script :

public static client void lookupWorkerByLegalEntity
(FormStringControl _lookupctrl, Int64 _LegalEntity)
{
SysTableLookup sysTableLookup;
Query query = new Query();
QueryBuildDataSource queryBuildDataSource, queryBuildDataSource1;
;
SysTableLookup = SysTableLookup::newParameters(tableNum(HcmWorker), _lookupctrl);
sysTableLookup.addLookupfield(fieldNum(HcmWorker, PersonnelNumber));
sysTableLookup.addLookupfield(fieldNum(HcmWorker, Person));
sysTableLookup.addLookupMethod(tableMethodStr(HcmWorker,workerRelationType));
queryBuildDataSource = query.addDataSource(tableNum(HcmWorker)); queryBuildDataSource1 = queryBuildDataSource.addDataSource(tableNum(HcmEmployment));
queryBuildDataSource1.joinMode(JoinMode::ExistsJoin);
queryBuildDataSource1.relations(true);
queryBuildDataSource1.addRange(fieldNum(HcmEmployment, LegalEntity))
.value(SysQuery::value(_LegalEntity)); sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}

2. Overide method Lookup in datasource field in form which lookup to worker with this script :

public void lookup(FormControl _formControl, str _filterStr)
{
HcmWorker::lookupWorkerByLegalEntity(_formControl, CompanyInfo::find().RecId);
}