How to Inject Custom Logic into D365 F&O SSRS Reports Using Controller & Contract Extension / Apply Custom logic on DP class
The Scenario:
I had to customize the Ledger Journal report (LedgerJournalCopy.PayableVouchers) by adding a custom logic flag that can be controlled dynamically. This allows different execution paths in the data provider based on runtime decisions.
And to run a custom logic through controller if the menuitem is clicked who has this controller class
· Step:1 Extend the Contract Class
[ExtensionOf(ClassStr(LedgerJournalContract))]
final class JALedgerJournalContract_Extension
{
private str runCustomLogic;
[DataMemberAttribute("RunCustomLogic")]
public str parmRunCustomLogic(str _runCustomLogic = runCustomLogic)
{
runCustomLogic = _runCustomLogic;
return runCustomLogic;
}
}
Explanation: We add a new string parameter RunCustomLogic using a standard extension approach. This will hold the value to control logic in the RDP class
· Step 2: Custom Controller Class
public class PayableVoucherController extends LedgerJournalController
{
public static void main(Args _args)
{
PayableVoucherController controller = new PayableVoucherController();
controller.parmReportName(ssrsReportStr(LedgerJournalCopy, PayableVouchers));
controller.parmArgs(_args);
controller.parmShowDialog(false);
LedgerJournalContract baseContract = controller.parmReportContract().parmRdpContract() as LedgerJournalContract;
if (baseContract)
{
baseContract.parmRunCustomLogic("Yes");
}
if (_args.record() && _args.record().TableId == tableNum(LedgerJournalTable))
{
LedgerJournalTable journal = _args.record();
Query query = controller.parmReportContract().parmQueryContracts().lookup(controller.getFirstQueryContractKey()).query();
QueryBuildDataSource qbds = query.dataSourceTable(tableNum(LedgerJournalTable));
if (qbds)
{
qbds.clearRanges();
qbds.addRange(fieldNum(LedgerJournalTable, JournalNum)).value(queryValue(journal.JournalNum));
}
}
controller.setRange(_args, controller.parmReportContract().parmQueryContracts().lookup(controller.getFirstQueryContractKey()));
controller.startOperation();
}
}
Explanation: We set the RunCustomLogic parameter to "Yes" and apply custom filtering on LedgerJournalTable. This ensures that only the relevant journal data is processed.
Step 3 : Add condition in your DP class
[Extension of (Classstr(LedgerJournalDp))]
{
ProcessReport()
{
Next processReport();
if (baseContract && baseContract.parmRunCustomLogic() == "Yes")
{
// Custom business logic here
} } }
Explanation: In the data provider, we check the contract parameter and execute the required custom logic accordingly.
Software Engineer | ERP Developer | Microsoft Dynamics 365 | Technical Consultant
5dUseful 👏
Software Engineer | Microsoft Dynamics ERP Developer | X++
1wThanks for sharing, Haseeb