Saturday, March 16, 2024

SSRS report for current record

SSRS report in Dynamics 365 FO to get the current record from the form and run for it


Contract class:

[DataContractAttribute]
class LS_SafteyCalendarReportContract
{
    str ID;

    [DataMemberAttribute('ID')]
    public str parmID(str _ID = ID)
    {
        ID = _ID;
        return ID;
    }

}




Controller class:

class LS_SafteyCalendarReportController extends SrsReportRunController
{
    public static LS_SafteyCalendarReportController construct()
    {
        return new LS_SafteyCalendarReportController();
    }

    public static void main(Args args)
    {
        LS_SafteyCalendarReportController controller = LS_SafteyCalendarReportController::construct();

        controller.parmArgs(args);
        controller.parmReportName(ssrsReportStr(LS_SafteyCalendarReport, Report));
        controller.parmShowDialog(false);
        controller.startOperation();
    }

    protected void prePromptModifyContract()
    {
        LS_SafetyCalendarHeader         LS_SafetyCalendarHeaderLocal;
        LS_SafteyCalendarReportContract contract;
        FormDataSource                  fds;
        contract = this.parmReportContract().parmRdpContract() as LS_SafteyCalendarReportContract;
        fds = args.record().dataSource();
        LS_SafetyCalendarHeaderLocal = args.record();
        contract.parmID(LS_SafetyCalendarHeaderLocal.IDD);
    }

}




DP Class:

[SRSReportParameterAttribute(classStr(LS_SafteyCalendarReportContract))]
class LS_SafteyCalendarReportDP extends SRSReportDataProviderBase
{
    LS_SafteyCalendarTmp reportTmp;

    [SRSReportDataSetAttribute(tableStr(LS_SafteyCalendarTmp))]
    public LS_SafteyCalendarTmp getTmp()
    {
        select reportTmp;
        return reportTmp;
    }

    public void processReport()
    {
        LS_SafteyCalendarReportContract contract = this.parmDataContract() as LS_SafteyCalendarReportContract;
        
        LS_SafetyCalendarHeader LS_SafetyCalendarHeaderLocal;
        
        anytype x = contract.parmID();
        
        select firstonly LS_SafetyCalendarHeaderLocal
            where LS_SafetyCalendarHeaderLocal.IDD == contract.parmID();
        
        reportTmp.clear();
        reportTmp.EmployeeName = HcmWorker::find(LS_SafetyCalendarHeaderLocal.HcmWorkerRecId).name();
        reportTmp.insert();
    }

}


Just create a report, put that report in an output menu item, and apply that menu item to the relevant form