Eg. We had a requirement at a customer where the HR wanted the records to be restricted as per the position hierarchy. So if a manager logs in he should be able to see managers reporting to him and any subordinates below these managers.
The answer to the above problem is to implement the My construct pattern for security. My Construct uses temporary tables of type TempDB which are populated using a table method called XDS(). This method is available for developers to write X++ logic to populate the temporary table. After the temporary table is populated, subsequent policy queries can use this temporary table.
In MyConstructs, we have the ability to refresh the data either PerSession or PerInvocation.
Below is the code for an overridden XDS method of a table
public RefreshFrequency xds()
List workerList = new List(Types::Int64);
List subordinate(HcmWorkerRecId _worker,List _workerList)
while select positionWorkerAssignment join positionHierarchy
where positionWorkerAssignment.Position == positionHierarchy.Position &&
positionHierarchy.ParentPosition == HcmWorker::getPrimaryPosition(_worker) &&
positionHierarchy.PositionHierarchyType == HcmPositionHierarchyType::lineHierarchyType()
where hcmEmployment.Worker == positionWorkerAssignment.Worker
_workerlist = subordinate(positionWorkerAssignment.Worker,_workerlist);
workerList = subordinate(currentWorker(),workerList);
workerListEnumerator = workerList.getEnumerator();
mySubordinate.Worker = workerListEnumerator.current();