Chain of Command vs PostHandlerFor in D365 Finance & Operations SSRS Reports
X++ PostHandlerFor vs CoC Extension Usage on DP Classes
- Option A: Wrap the DP method with Chain of Command (CoC)
- Option B: Attach a PostHandlerFor event handler to the DP’s
processReport
This blog walks through both approaches, outlines when to use each, and the key behaviors.
Option A — Chain of Command
next. Microsoft explicitly positions this as the way to extend logic without event handlers. For more detail, refer to Microsoft's documentation on method wrapping with Chain of Command and extensibility attributes.- You must call
next(except replaceable cases) and you can run logic before or after it. - CoC applies only if the method is wrappable (e.g., not blocked by
finalor[Wrappable(false)]). -
CoC is generally easier to follow/debug and behaves like a controlled “method wrapping” pipeline.
[ExtensionOf(classStr(SalesInvoiceDP))]
final class SsiSalesInvoiceDP_Extension
{
public void processReport()
{
next processReport();
SalesInvoiceTmp invoiceTmp = this.getSalesInvoiceTmp();
ttsbegin;
while select forUpdate invoiceTmp
{
// TODO Perform custom operation
invoiceTmp.update();
}
ttscommit;
}
}
Option B — PostHandlerFor on processReport
- You don’t call
next. The base method already ran (post) or hasn’t run yet (pre). - You access state via
XppPrePostArgsandargs.getThis(). - You have less explicit control of composition and ordering than CoC, and it can break more easily across updates.
class SsiSalesInvoiceDPHandler
{
[PostHandlerFor(classStr(SalesInvoiceDP), methodStr(SalesInvoiceDP, processReport))]
public static void SalesInvoiceDP_Post_processReport(XppPrePostArgs args)
{
SalesInvoiceDP dp = args.getThis() as SalesInvoiceDP;
if (!dp)
{
return;
}
SalesInvoiceTmp invoiceTmp = dp.getSalesInvoiceTmp();
ttsbegin;
while select forUpdate invoiceTmp
{
// TODO Perform custom operation
invoiceTmp.update();
}
ttscommit;
}
}
Final Thoughts
Choosing between Chain of Command and PostHandlerFor comes down to extensibility, stability, and long‑term maintainability. When Chain of Command is available, it’s typically the safer and more predictable option, while PostHandlerFor remains useful for edge cases and legacy scenarios.
If you’re unsure which approach is right for your reporting or customization needs, the Stoneridge Support Team can help evaluate your requirements and recommend a solution.
Under the terms of this license, you are authorized to share and redistribute the content across various mediums, subject to adherence to the specified conditions: you must provide proper attribution to Stoneridge as the original creator in a manner that does not imply their endorsement of your use, the material is to be utilized solely for non-commercial purposes, and alterations, modifications, or derivative works based on the original material are strictly prohibited.
Responsibility rests with the licensee to ensure that their use of the material does not violate any other rights.


