Monday, September 12, 2016

Worker Managerial Hirearchy Above and below Levels ax 2012

//Worker Managerial Hirearchy Above and below Levels ax 2012
static void CheckManagerialHirearchy(Args _args)
{
    Query       query = new Query();
    QueryBuildDataSource    qbdsWorker;
    QueryRun        qr;
    HcmWorker           hcmWorker,hcmWorkerChk;
    HcmPositionWorkerAssignment         HcmPositionWorkerAssignment;
    container           allowedworkers,conWorker;
    int i;
   
    //Use AX default view HcmWkrPositionHierarchyView
    container allowedworkersCHeck(RecId _RecId,NoYes    _noYes = NoYes::Yes)
    {
        container allowedWorker = conNull();
        ReportingEmployees  reportemployee; //View
        //View Dataasource HCMPositionHirearchy,HCmPosition,HCMWorkerAssignment,HCMWorker)
        //View fields--> 1) HCMPositionHirearchy-ParentPosition 2) HCMPositionHirearchy-POsition 3) HCMWorker-PersonnelNumber
        ;
        if(_noYes == NoYes::Yes)        // Above level
        {
            while select reportemployee where reportemployee.Position == _RecId
            {  
                allowedWorker += HcmPositionWorkerAssignment::findByPosition(reportemployee.ParentPosition).Worker;
            }
        }
        else // Below level
        {
            while select reportemployee where reportemployee.ParentPosition == _RecId
            {  
                allowedWorker += HcmPositionWorkerAssignment::findByPosition(reportemployee.Position).Worker;
            }   
        }
        return allowedWorker;
    }
    ;
    qbdsWorker  = query.addDataSource(tableNum(HcmWorker));
    hcmWorker   =  HcmWorker::find(DirPersonuser::findUserWorkerReference(curUserId()));
    //info(curUserId());
    if(hcmWorker)
    {
        //info(strFmt("%1",hcmWorker.RecId));
        select firstOnly Position from HcmPositionWorkerAssignment
                where HcmPositionWorkerAssignment.Worker == hcmworker.RecId;
        //qbdsWorker.addRange(fieldNum(HcmWorker,RecId)).value(queryValue(hcmWorker.RecId));
        allowedworkers = allowedworkersCHeck(HcmPositionWorkerAssignment.Position,NoYes::No);
        //info(strFmt("%1",HcmPositionWorkerAssignment.Position));
        for(i =1;i<=conLen(allowedworkers);i++)
        {
            qbdsWorker.addRange(fieldNum(HcmWorker,RecId)).value(queryValue(conPeek(allowedworkers,i)));
        }
    }
    else
    {
        qbdsWorker.addRange(fieldNum(HcmWorker,RecId)).value(queryValue(0));
    }
    qr = New QueryRun(query);
    while (qr.next())
    {
        hcmWorkerChk = qr.get(tableNum(HcmWorker));
        info(strFmt("%1,%2,%3,%4,%5",hcmWorkerChk.PersonnelNumber,hcmWorkerChk.Person,hcmWorkerChk.name(),hcmWorkerChk.primaryDepartmentName(),HcmpositionDetail::findByPosition(HcmPosition::findByPosition(hcmWorkerChk.primaryPositionId()).RecId).Description));//,hcmWorkerChk.
    }
   
   
}

No comments:

Post a Comment

Convert Call stack to readable format in D365FO X++

//Input --container _xppCallStack = xSession::xppCallStack();  Public static str POL_formatXppCallStack(container _xppCallStack, int _skipFr...