Hi All,
I have previously asked this question for an AR Invoice in a different approach. But I was unable to resolve it using the replies of that question because of some issues(Release method is not triggering when we process invoices from a process screen).
However, Now I want to attach a report pdf to files section of an AP Invoice through Release AP Documents screen. I tried to override Release action in APPaymentEntry graph. But it is not triggering when releasing invoices through Release AP Documents screen. Then I tried the below code snippet & it is triggering for each AP Invoice. There are no errors in the code. But file is not attaching as expected. Below is my code.
Acumatica Version : 21.213
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using PX.Common;
using PX.Data;
using PX.Data.DependencyInjection;
using PX.Data.WorkflowAPI;
using PX.LicensePolicy;
using PX.Objects.Common;
using PX.Objects.Common.Extensions;
using PX.Objects.Common.Bql;
using PX.Objects.Common.Discount;
using PX.Objects.GL;
using PX.Objects.GL.FinPeriods;
using PX.Objects.CM;
using PX.Objects.CS;
using PX.Objects.CR;
using PX.Objects.CT;
using PX.Objects.PM;
using PX.Objects.TX;
using PX.Objects.IN;
using PX.Objects.IN.Services;
using PX.Objects.CA;
using PX.Objects.BQLConstants;
using PX.Objects.EP;
using PX.Objects.PO;
using PX.Objects.SO;
using PX.Objects.DR;
using PX.Objects.AR;
using PX.TM;
using AP1099Hist = PX.Objects.AP.Overrides.APDocumentRelease.AP1099Hist;
using AP1099Yr = PX.Objects.AP.Overrides.APDocumentRelease.AP1099Yr;
using PX.Objects.GL.Reclassification.UI;
using Branch = PX.Objects.GL.Branch;
using CRLocation = PX.Objects.CR.Standalone.Location;
using PX.Objects.AP.BQL;
using PX.Objects.Common.GraphExtensions.Abstract;
using PX.Objects.Common.GraphExtensions.Abstract.DAC;
using PX.Objects.Common.GraphExtensions.Abstract.Mapping;
using PX.Objects.Extensions.CostAccrual;
using PX.Data.BQL.Fluent;
using PX.Data.BQL;
using PX.Objects;
using PX.Objects.AP;
using PX.Data.Reports;
using PX.Reports.Data;
using PX.SM;
using PX.Reports;
namespace PX.Objects.AP
{
public class APReleaseProcess_Extension : PXGraphExtension<APReleaseProcess>
{
[InjectDependency]
protected IReportLoaderService ReportLoader { get; private set; }
[InjectDependency]
protected internal PX.Reports.IReportDataBinder ReportDataBinder { get; private set; }
#region Event Handlers
public delegate List<APRegister> ReleaseDocProcDelegate(JournalEntry je, APRegister doc, Boolean isPrebooking, ref List<INRegister> inDocs);
[PXOverride]
public List<APRegister> ReleaseDocProc(JournalEntry je, APRegister doc, Boolean isPrebooking, ref List<INRegister> inDocs, ReleaseDocProcDelegate baseMethod)
{
var retVal = baseMethod(je, doc, isPrebooking, ref inDocs);
APInvoice apInvoice = new PXSelect<APInvoice, Where<APInvoice.refNbr, Equal<Required<APInvoice.refNbr>>,
And<APInvoice.docType, Equal<Required<APInvoice.docType>>>>>(Base).Select(doc.RefNbr, doc.DocType);
if (apInvoice == null)
{
return retVal;
}
//Report Paramenters
Dictionary<String, String> parameters = new Dictionary<String, String>();
parameters["DocType"] = apInvoice.DocType;
parameters["RefNbr"] = apInvoice.RefNbr;
PXReportSettings settings = new PXReportSettings("MA31099");
//Report Processing
PX.Reports.Controls.Report report =
ReportLoader.CheckIfNull(nameof(ReportLoader)).LoadReport("MA31099", null);
ReportLoader.InitReportParameters(report, parameters, settings, false);
PX.Reports.Data.ReportNode reportNode =
ReportDataBinder.CheckIfNull(nameof(ReportDataBinder)).ProcessReportDataBinding(report);
//Generation PDF
byte[] data = PX.Reports.Mail.Message.GenerateReport(reportNode,
RenderType.FilterPdf).First();
PX.SM.FileInfo file = new PX.SM.FileInfo(reportNode.ExportFileName + "- " + apInvoice.RefNbr + ".pdf", null, data);
var uploadFileMaintenance = PXGraph.CreateInstance<UploadFileMaintenance>();
uploadFileMaintenance.SaveFile(file);
PXNoteAttribute.AttachFile(Base.Caches[typeof(APInvoice)], apInvoice , file);
return retVal;
}
#endregion
}
}
As an alternative options I tried updating cache as below as well. But no luck.
Base.Caches[typeof(APInvoice)].Insert(apInvoice);
Do you have any idea about this?