Saturday, June 29, 2013

Adding Report to AP or AR screens. Unhiding Automation Steps Links.

Hi Everyone,

While adding report to some of the screens might be an easy task, for AR or AP we have only choice of predefined hard coded reports.

So our goal for today to add report to get something like this:




Normally we do it via Automation Steps, but once you get there you will realise, we can't add any other report to the list, but only predefined existing reports.
I wanted to extend this list with newly created user report. So as usual, I added a report to a site map, it appeared in the reports section of the AP Module.

 

And because AR/AP modules are using predefined report list we will have to customize the Report method of the APDataEntryGraph
To do it, I called up Source Code Browser, found this graph, and copied Report method to my customization. Then I added new report to it:

[PXUIField(DisplayName = "Reports", MapEnableRights = PXCacheRights.Select)]
[PXButton]

protected override IEnumerable Report(PXAdapter adapter,
[PXString(8)]
[PXStringList(new string[] { "AP610500", "AP622000", "AP622500", "AP610720"}, new string[] { "AP Edit", "AP Register Detailed", "AP Payment Register", "AP Payment Voucher" })]
string reportID
)
{
APPayment doc = Document.Current;
if (doc!=null)
{
object FinPeriodID;

switch (reportID)
{
case "AP610500":
{
Dictionary<string, string> parameters = new Dictionary<string, string>();
parameters["DocType"] = doc.DocType;
parameters["RefNbr"] = doc.RefNbr;
throw new PXReportRequiredException(parameters, reportID, "Report");
}
case "AP622000":
{
Dictionary<string, string> parameters = new Dictionary<string, string>();
parameters["PeriodID"] = (FinPeriodID = this.Caches[typeof(APPayment)].GetValueExt<APRegister.finPeriodID>(doc)) is PXFieldState ? (string)((PXFieldState)FinPeriodID).Value : (string)FinPeriodID;
parameters["DocType"] = doc.DocType;
parameters["RefNbr"] = doc.RefNbr;
throw new PXReportRequiredException(parameters, reportID, "Report");
}
case "AP622500":
{
Dictionary<string, string> parameters = new Dictionary<string, string>();
parameters["DocType"] = doc.DocType;
parameters["RefNbr"] = doc.RefNbr;
parameters["PeriodID"] = (FinPeriodID = this.Caches[typeof(APPayment)].GetValueExt<APRegister.finPeriodID>(doc)) is PXFieldState ? (string)((PXFieldState)FinPeriodID).Value : (string)FinPeriodID;
throw new PXReportRequiredException(parameters, reportID, "Report");
}
case "AP610720":
{
Dictionary<string, string> parameters = new Dictionary<string, string>();
parameters["DocType"] = doc.DocType;
parameters["RefNbr"] = doc.RefNbr;
parameters["PeriodID"] = (FinPeriodID = this.Caches[typeof(APPayment)].GetValueExt<APRegister.finPeriodID>(doc)) is PXFieldState ? (string)((PXFieldState)FinPeriodID).Value : (string)FinPeriodID;
throw new PXReportRequiredException(parameters, reportID, "Report");
}

}
}
return adapter.Get();
}
 
In my case I added report AP610720.
Please note we need to add a button, its right on top of the code, also we have to place this code into our screen, in my case Checks and Payments.

Right after you added this code, option will become enabled to choose in Automation Steps newly added report.

Have a great weekend,

Sergey.

1 comment:

  1. Hi sergey! where did you put this snippet? on the APDataEntry ? or in the APPaymentsEntry? I tried to put it in the APinvoiceEntry and I encountered some errors. and I would also ask if you could update the snippet for Acumatica 5. Thanks!

    ReplyDelete