如何在D365FO创建SSRS报表(二)Controller Class(how-to-create-ssrs-report-in-d365fo-part2-controller-class)

Report controller

继承SrsReportRunController

如果没有特殊要求,以下代码就可以搞定。

public class Demo_InventJournalTransTransferController extends SrsReportRunController
{
 
    public static void main(Args _args)
    {
        Demo_InventJournalTransTransferController controller 
          = new Demo_InventJournalTransTransferController();
 
        controller.parmReportName(ssrsReportStr(Demo_InventJournalTransTransfer, Report));
        controller.parmDialogCaption("@Demo954");
        controller.parmArgs(_args);
        controller.startOperation();
    }
}

多选

如果需要打印用户所选的数据,多选需要用到 MultiSelectionHelper

public class Demo_InventJournalTransTransferController extends SrsReportRunController
{
    ......
 
    public void preRunModifyContract()
    {
        Demo_InventJournalTransTransferContract contract 
          = this.parmReportContract().parmRdpContract() as Demo_InventJournalTransTransferContract;        
    }
 
    public void prePromptModifyContract()
    {
        Demo_InventJournalTransTransferContract     contract;
 
        contract = this.parmReportContract().parmRdpContract() as Demo_InventJournalTransTransferContract;
 
        this.setRanges(
           this.parmReportContract().parmQueryContracts().lookup(this.getFirstQueryContractKey())
           , contract);
    }
 
    public void setRanges(
        Query _query,
        Demo_InventJournalTransTransferContract _contract)
    {
        MultiSelectionHelper    multiSelectionHelper;
 
        if (this.parmArgs().dataset() == tableNum(InventJournalTable) && this.parmArgs().caller())
        {
            _query.dataSourceTable(tableNum(InventJournalTable)).clearRanges();
            multiSelectionHelper = MultiSelectionHelper::createFromCaller(this.parmArgs().caller());
            multiSelectionHelper.createQueryRanges(_query.dataSourceTable(tableNum(InventJournalTable))
               , fieldStr(InventJournalTable, JournalId));
        }
 
    }
 
}

如果需要根据Print management的设定来打印,请参考文章: