Wednesday 6 February 2019

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

}
}

4 comments:

  1. container selectedFields = [multiSelectTableNum, fieldName2id(multiSelectTableNum, fieldStr(VendTable, AccountNum))];

    what is?

    ReplyDelete
  2. Just wanna admit that this is invaluable , Thanks for taking your time to write this. Homepage

    ReplyDelete
  3. iam new at this i need to put all code in contract class

    ReplyDelete

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