D365: X++ code to add custom lookup on worker to show specific workers team workers only
/// <summary>
///
///
</summary>
///
<param name = "_formReferenceControl"></param>
///
<returns></returns>
public Common lookupReference(FormReferenceControl _formReferenceControl)
{
SysReferenceTableLookup sysTableLookup = SysReferenceTableLookup::newParameters(tablenum(HcmWorker), _formReferenceControl, true);
Query query
= new Query();
QueryBuildDataSource
queryBuildDataSource;
QueryBuildRange
queryBuildRange;
HcmPosition
hcmPositionPareant;
HcmPositionHierarchy
hcmPositionHierarchy;
utcdatetime _validFrom
= DateTimeUtil::utcNow();
utcdatetime
_validTo = _validFrom;
HcmPositionWorkerAssignment workerAssignment;
HcmWorker
workerTeam;
;
sysTableLookup.addLookupField(fieldNum(HcmWorker, PersonnelNumber));
sysTableLookup.addLookupField(fieldNum(HcmWorker, Person));
hcmPositionPareant = HcmPosition::find(HcmWorker::getPrimaryPosition(HcmWorkerLookup::currentWorker()));
queryBuildDataSource =
query.addDataSource(tablenum(HcmWorker));
while select ValidTimeState(_validFrom, _validTo) hcmPositionHierarchy
where hcmPositionHierarchy.ParentPosition
== hcmPositionPareant.RecId
{
while select ValidTimeState(_validFrom, _validTo) workerAssignment
where workerAssignment.Position ==
hcmPositionHierarchy.Position
{
workerTeam = HcmWorker::find(workerAssignment.Worker);
queryBuildRange =
queryBuildDataSource.addRange(fieldNum(HcmWorker,RecId));
queryBuildRange.value(int642str(workerTeam.RecId));
}
}
sysTableLookup.parmQuery(query);
return sysTableLookup.performFormLookup();
}
}
Comments
Post a Comment