Tuesday, 3 January 2023

Call different report design in Purchase order confirmation report

We often need to update report designs or call different report designs based on scenarios. Print management can help calling different report designs, but only if a specific call is made from the ‘Use Print Management’ button and the designs are already set up.


In case, if print management has set up to send report via email then ‘Use print management’ button will not show a report on screen. We need to go back to setup again and change email setup to ‘Screen’ in order to view the report, but that can be cumbersome updating setup every time. 


This can be resolved by calling our custom designs on ‘Copy’ and ‘Original’ buttons.

This blog has a solution that describes how the different report designs are called in PO confirmation report.


As shown on PO confirmations journal form we have options to preview report as below.


We need to create extensions of these three menu items so that we can assign extended controller class to it, which would call our custom report design.

  • PurchPurchaseOrderCopy.DemoExtension
  • PurchPurchaseOrderOriginal.DemoExtension
  • PurchPurchaseOrder.DemoExtension

Now, extend a controller class, PurchPurchaseOrderController.

1
2
3
4
5
6
7
class DemoPurchPurchaseOrderControllerExt extends PurchPurchaseOrderController
{
    public static DemoPurchPurchaseOrderControllerExt construct()
    {
        return new DemoPurchPurchaseOrderControllerExt();
    }
}

Add a main() method in extended class. This can be called from menu item. Here we need to update a custom report design name that we want to be called. main() method of parent class PurchPurchaseOrderController can be referred here.


1
2
3
4
5
6
7
8
9
10
11
12
public static void main(Args _args)
{
    SrsReportRunController formLetterController =
    DemoPurchPurchaseOrderControllerExt::construct();
    DemoPurchPurchaseOrderControllerExt controller;  
    controller = formLetterController;
    controller.parmArgs(_args);
    controller.initDataContract(_args,
    ssrsReportStr(DemoPurchPurchaseOrder, DemoReport));
    controller.parmShowDialog(false);
    controller.startOperation();
}

Updating report design in main() method only doesn’t work. We need to add a logic in OutputReport() method as well. This method is called from all three menu items. (Copy, Original and Print Management)


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
protected void outputReport()
{
    SRSCatalogItemName reportDesignToPrint;  
    super();
    //this.parmArgs() will give you the args() from parent class by which
    //you can access the required details if different design needs to be
    //printed based on scenarios. e.g. menuItemName()
       
    //Update required design as given below
    reportDesignToPrint= ssrsReportStr(DemoPurchPurchaseOrder,
    DemoReport);
    this.parmReportName(reportDesignToPrint);
    this.parmReportContract().parmReportName(reportDesignToPrint);
    formletterReport.parmReportRun().settingDetail()
    .parmReportFormatName(reportDesignToPrint);       
}

Now create an extension of class PrintMgmtDelegatesHandler as well.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
[ExtensionOf(classStr(PrintMgmtDelegatesHandler))]
final class DemoPrintMgmtDelegatesHandler_Extension
{
    protected static PrintMgmtReportFormatName
    getDefaultReportFormat(PrintMgmtDocumentType _docType)
    {
      PrintMgmtReportFormatName   reportDesignToPrint, reportName; 
 
      //next call;
      reportName = next getDefaultReportFormat(_docType);
 
      //Custom logic can be added here to update scenario based design
      //Condition based logic if any 
      reportDesignToPrint = ssrsReportStr(DemoPurchPurchaseOrder,
      DemoReport);
      //Custom logic - end
 
        switch (_docType)
        {
            case PrintMgmtDocumentType::PurchaseOrderConfirmationRequest:
            reportName = reportDesignToPrint;
        }
         
        return reportName;
    }
}

It is now necessary to assign the extended controller class to the extended menu items so that, upon call-out, custom logic will be executed.


Make sure to clear usage data after updating any print management setup or any changes to controller classes because AX may continue to use the older copy that may differs the result.

No comments:

Post a Comment

Filtering Company-Specific Product Templates - SysRecordTmpTemplate lookup

Hi Techies - Recently I have come across a requirement where I needed to display product templates specific to a selected company for a give...