1
votes

Basically i want to create a new action button On Print Invoice and Memos screen to print a report for selected invoices.

Why we are creating new action button is, here we need to print different formats for each invoice (SO type) so when user selects 3 different records in grid for an example 1. INV1234 and so type is TS then i need to print xyz report 2. INV9875 and this has not created through SO then i need to print ABC report 3. CRM4567 and SO type is TS (like above 1 option)

so here 1 & 3 should print in one page (Like same how process button is working in default acumatica) 2 option report should print in new tab.

If i get a sample code on to print same report in single page and other one in another tab is fine.

Below is the code

public PXAction<PrintInvoicesFilter> PrintReport;
        [PXUIField(DisplayName = "Print Sales Invoice with Price", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
        [PXLookupButton]
        public virtual IEnumerable printReport(PXAdapter adapter, [PXString] string reportID)
        {
            PXReportRequiredException ex = null;

            foreach (ARInvoice doc in Base.ARDocumentList.Cache.Cached)
            {
                var parameters = new Dictionary<string, string>();
                if (doc.Selected == true)
                {
ARTran TranData = PXSelectReadonly<ARTran, Where<ARTran.tranType, Equal<Required<ARTran.tranType>>,
                        And<ARTran.refNbr, Equal<Required<ARTran.refNbr>>>>>.Select(Base, doc.DocType, doc.RefNbr);

                    if (TranData != null)
                    {
                        if (TranData.SOOrderType == "WS" || TranData.SOOrderType == "WO" || TranData.SOOrderType == "TS" || TranData.SOOrderType == "IM")
                        {
                            if (reportID == null) reportID = "KR501011";

                            if (reportID == "KR501011")
                            {
                                parameters["DocType"] = doc.DocType;
                                parameters["RefNbr"] = doc.RefNbr;
                            }
                            ex = PXReportRequiredException.CombineReport(ex, "KR501011", parameters,false);
                        }
if (TranData.SOOrderType == "RX")
                        {
                            if (reportID == null) reportID = "KR501016";

                            if (reportID == "KR501016")
                            {
                                parameters["DocType"] = doc.DocType;
                                parameters["RefNbr"] = doc.RefNbr;
                            }
                            ex = PXReportRequiredException.CombineReport(ex, "KR501016", parameters,false);
                        }

                        if (string.IsNullOrEmpty(TranData.SOOrderType))
                        {
                            if (reportID == null) reportID = "KR501038";

                            if (reportID == "KR501038")
                            {
                                parameters["DocType"] = doc.DocType;
                                parameters["RefNbr"] = doc.RefNbr;
                            }
                            ex = PXReportRequiredException.CombineReport(ex, "KR501038", parameters,false);
                        }
                    }
                }
            }
if (ex != null)
            {
                ex.Mode = PXBaseRedirectException.WindowMode.New;
                ex.SeparateWindows = false;
                throw ex;
            }

Thanks in advance.

1
Can some one please help me on this to print multiple report ID on one click - BhavyaSri

1 Answers

0
votes

Redirecting to multiple report or combining multiple report in a single document can only be achieved with method PXReportRequiredException.CombineReport.

The redirection exception has two options to control how the reports are combined:

  1. Print all report as a single PDF file – ex.SeparateWindows = false;

  2. Open each separate report in a new tab – ex.SeparateWindows = true;

Your requirement asked for 1 and 2 at the same time which is not possible. You can only choose option 1 or 2. To get both you would need two actions button to launch the reports.

The reason for the limitation is because to redirect to a report you have to throw an exception. Once the exception is thrown you can't execute code anymore to launch a new report. It is possible to print multiple reports with a single exception as explained below but you have to choose between all reports in same tab (same document) or one report per tab (one document per report).

Blog Source: https://asiablog.acumatica.com/2017/03/launch-multiple-reports-with-one-exception.html

Code example from that blog source:

PXReportRequiredException ex = null;

if(row.ARRefNumber != null)
{
  Dictionary<string, string> dictionary = new Dictionary<string, string>();
  dictionary["DocType"] = row.ARDocType;
  dictionary["RefNbr"] = row.ARRefNumber;
  ex = PXReportRequiredException.CombineReport(ex, row.ARBatchNumber == null ? "AR610500" : "AR622000", dictionary, false);
}

if (row.APRefNumber != null)
{
  APInvoice inv = PXSelectorAttribute.Select<DocHeader.aPRefNumber>(Document.Cache, row) as APInvoice;
  Dictionary<string, string> dictionary = new Dictionary<string, string>();
  dictionary["DocType"] = row.APDocType;
  dictionary["RefNbr"] = row.APRefNumber;
  dictionary["PeriodTo"] = PX.Objects.GL.OpenPeriodAttribute.FormatForDisplay(inv.FinPeriodID);
  dictionary["PeriodFrom"] = PX.Objects.GL.OpenPeriodAttribute.FormatForDisplay(inv.FinPeriodID);
  ex = PXReportRequiredException.CombineReport(ex, row.APBatchNumber == null ? "AP610500" : "AP622000", dictionary, false);
}

if (ex != null)
{
  ex.Mode = PXBaseRedirectException.WindowMode.New;
  ex.SeparateWindows = true;
  throw ex;
}