Sunday, June 5, 2022

Create multi selection lookup in D365FO for SSRS report.

SSRS Multi-Selection Lookup

Hi All,

Let's learn about multi-selection lookup in SSRS report and basics of SSRS reporting.

Requirement: Add voucher lookup from VendTrans on SSRS report dialog.

Step 1: Create new project area

Step 1 Image

Select custom model and mark Synchronize DB on build true and click apply.

Step 1 Image 2

Step 2: Create temporary table

Step 2 Image

Step 3: Create UI builder class

public final class TestMultiSelectionUIBuilder extends SysOperationAutomaticUIBuilder
{
    DialogField dialogVoucherId;
    public void VoucherIdLookup(FormStringControl _control)
    {
        Query query = new Query();
        QueryBuildDataSource qbds;
        container conVoucherID;

        qbds = query.addDataSource(tableNum(VendTrans));
        qbds.addSelectionField(fieldNum(VendTrans,Voucher));

        SysLookupMultiSelectGrid::lookup(query, _control, _control, _control, conVoucherID);
    }

    public void postBuild()
    {
        TestMultiSelectionLookupContract contract;
        super();
        contract = this.dataContractObject() as TestMultiSelectionLookupContract;
        dialogVoucherId = this.bindInfo().getDialogField(this.dataContractObject(), methodStr(TestMultiSelectionLookupContract, parmVoucherId));
        dialogVoucherId.registerOverrideMethod(methodStr(FormStringControl, lookup), methodStr(TestMultiSelectionUIBuilder, VoucherIdLookup), this);
        if (dialogVoucherId)
        {
            dialogVoucherId.lookupButton(2);
        }
    }

    public void postRun()
    {
        //super();
    }
}

Step 4: Create Contract class

[DataContractAttribute, SysOperationContractProcessingAttribute(classStr(TestMultiSelectionUIBuilder))]
public final class TestMultiSelectionLookupContract
{
    List voucherlist;

    [DataMemberAttribute("Exclude voucher"), AifCollectionTypeAttribute("Exclude voucher", Types::String), SysOperationLabelAttribute(literalStr("ExcludeVoucher")), SysOperationDisplayOrderAttribute('0')]
    public List parmVoucherId(List _listVoucherId = voucherlist)
    {
        voucherlist = _listVoucherId;
        return voucherlist;
    }
}

Step 5: Create DP class

[SRSReportParameterAttribute(classStr(TestMultiSelectionLookupContract))]
public final class TestMultiSelectionDP extends SRSReportDataProviderBase
{
    TestMultiSelectionTmp testMultiSelectionTmp;
    List voucherlist;
    str voucherStr;

    [SRSReportDataSetAttribute(tableStr(TestMultiSelectionTmp))]
    public TestMultiSelectionTmp getMTVendorCashForecastTmp()
    {
        select * from testMultiSelectionTmp;
        return testMultiSelectionTmp;
    }

    [SysEntryPointAttribute]
    public void processReport()
    {
        TestMultiSelectionLookupContract testMultiSelectionLookupContract = this.parmDataContract() as TestMultiSelectionLookupContract;
        ListIterator voucherlistIterator;
        voucherlist = testMultiSelectionLookupContract.parmVoucherId();

        if(voucherlist != null)
        {
            voucherlistIterator = new ListIterator(voucherlist);
            while (voucherlistIterator.more())
            {
                voucherStr += voucherlistIterator.value() + ',';
                voucherlistIterator.next();
            }
        }
        voucherStr = subStr(voucherStr, 1, strLen(voucherStr) - 1);
        info(voucherStr);

        // write your logic to insert data into temp table.
    }
}

Step 6: Create Report

Report Image

Step 7: Create Controller class

internal final class TestMultiSelectionLookupController extends SrsReportRunController
{
    public void new()
    {
        super();
        this.caption();
    }

    protected final str getReportName(TestMultiSelectionLookupContract _contract)
    {
        str reportNameLocal;

        reportNameLocal = ssrsReportStr(TestMultiSelectionReport,Test1);
        
        return reportNameLocal;
    }

    public ClassDescription caption()
    {
        return "Multi selection lookup";
    }

    public static void main(Args _args)
    {
        TestMultiSelectionLookupController  controller;

        controller = new TestMultiSelectionLookupController();
        controller.parmArgs(_args);
        controller.ParmReportName(ssrsReportStr(TestMultiSelectionReport,Test1));

        controller.startOperation();
    
    }

    protected void preRunModifyContract()
    {
        TestMultiSelectionLookupContract contract = this.parmReportContract().parmRdpContract() as TestMultiSelectionLookupContract;
        this.parmReportContract().parmReportName(this.getReportName(contract));
        super();
    }

}

Result:

Result Screenshot

2 comments:

  1. Hi Vijay,
    I'm following the same to create multi selection look up after seleting the multi value from the look up does not display a tick mark against the values displayed in field as selected.

    ReplyDelete
  2. You can refer class "CFMPaymentRequestUpdFromSourceUIBuilder" and create lookup as they are creating then you will be able to see selected values.


    Link to new blog - https://d365fotechnicalblog.blogspot.com/2025/05/how-to-create-multiselection-lookup-in.html

    ReplyDelete

How to Create Multiselection Lookup in D365FO

How to Create Multiselection Lookup in D365FO How to Create Multiselection Lookup in D365FO In this blog p...