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;
}

Multi select lookup for SSRS report parameter in AX X++

Here is the sample code to create a multi-select Vendor lookup for the SSRS report.


















Create parm method in contract class
[DataContractAttribute,
 SysOperationContractProcessingAttribute(classStr(HRBankPayLetterVendorUIBuilder))]
class HRBankPayLetterVendorContract implements SysOperationValidatable
{
private List  vendAccount;

[DataMemberAttribute,
        SysOperationLabelAttribute('@HRP:PayrollVendorAccount'),
        AifCollectionTypeAttribute('@HRP:PayrollVendorAccount', Types::String),
        SysOperationDisplayOrderAttribute('1')]
       public List parmVendAccount(List _vendAccount = vendAccount)
       {
        vendAccount = _vendAccount;
        return vendAccount;
}
}


Create UI builder class
class HRBankPayLetterVendorUIBuilder extends SrsReportDataContractUIBuilder
{
private DialogField vendordf;
List   vendorList;
HRBankPayLetterVendorContract     contract;
public void postBuild()
{
        super();

        contract = this.dataContractObject();

        // binding dialogs with contract fields      

        vendordf = this.bindInfo().getDialogField(this.dataContractObject(),
            methodStr(HRBankPayLetterVendorContract, parmVendAccount));
       
}

public void postRun()
{
        this.lookupVendor();
}

private void lookupVendor()
{
        Query                   query = new Query();
        QueryBuildDataSource    qbd, qbdPerson;

        TableId     multiSelectTableNum = tableNum(VendTable);
        container   selectedFields      = [multiSelectTableNum, fieldName2id(multiSelectTableNum, fieldStr(VendTable, AccountNum))];
       
        qbd = query.addDataSource(tableNum(VendTable));
        qbd.addSelectionField(fieldNum(VendTable, AccountNum));       
        qbd.fields().dynamic(NoYes::No);
        qbd.fields().clearFieldList();
        qbd.fields().addField(fieldNum(VendTable, AccountNum));
        qbd.addRange(fieldNum(VendTable, HRRSPayrollVendor)).value(queryValue(NoYes::Yes));

        qbdPerson = qbd.addDataSource(tableNum(DirPartyTable));
        qbdPerson.fields().dynamic(NoYes::No);
        qbdPerson.fields().clearFieldList();
        qbdPerson.fields().addField(fieldNum(DirPartyTable, Name));
        qbdPerson.relations(true);       
       
        SysLookupMultiSelectCtrl::constructWithQuery(this.dialog().dialogForm().formRun(), vendordf.control(), query, false, selectedFields);

}
}

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...