Wednesday 6 February 2019

Current user department workers lookup


public Common lookupReference()
{
    Common ret;   
    QueryBuildDataSource queryBuildDataSource, qbds, qbds1, qbds2;
    RecId deparmtment;

    hcmworker currentWorker = hcmworker::find(HcmWorkerLookup::currentWorker());
               
    deparmtment =  OMOperatingUnit::findName(currentWorker.primaryDepartmentName(), OMOperatingUnitType::OMDepartment).RecId;
    SysReferenceTableLookup sysTableLookup = SysReferenceTableLookup::newParameters(tablenum(HcmWorker), this);

    Query query = new Query();

    queryBuildDataSource = query.addDataSource(tableNum(HcmWorker));

    qbds = queryBuildDataSource.addDataSource(tableNum(HcmPositionWorkerAssignment));
    qbds.joinMode(JoinMode::existsJoin);
    qbds.addLink(fieldNum(HcmWorker, RecId), fieldNum(HcmPositionWorkerAssignment, Worker));

    qbds1 = qbds.addDataSource(tableNum(HcmPosition));
    qbds1.joinMode(JoinMode::existsJoin);
    qbds1.addLink(fieldNum(HcmPositionWorkerAssignment, Position), fieldNum(HcmPosition, RecId));

    qbds2 = qbds1.addDataSource(tableNum(HcmPositionDetail));
    qbds2.joinMode(JoinMode::existsJoin);
    qbds2.addLink(fieldNum(HcmPosition, RecId), fieldNum(HcmPositionDetail, Position));
    qbds2.addRange(fieldNum(HcmPositionDetail, Department)).value(Queryvalue(deparmtment));

    sysTableLookup.addLookupfield(fieldnum(HcmWorker, PersonnelNumber));
    sysTableLookup.addLookupMethod(tableMethodStr(HcmWorker, Name));

    sysTableLookup.parmQuery(query);
    ret =  sysTableLookup.performFormLookup();   

    return ret;
}

No comments:

Post a Comment

Difference Between Edit And Display Method in Ax

Display Method: The display method means that the method’s return value is being displayed on a form or a report.  This value is fixed and c...