Skip to main content
Question

Attach PDF file with an action button 2023R2

  • August 22, 2024
  • 1 reply
  • 97 views

Hi guys, I have a problem, I have created an action that makes me attach an existing Report created by me.

The problem is that the attachment does not show information, if I go and run it on the same report screen if it shows information, here I show images, plus my code that makes the attachment.

Code:

public PXAction<PX.Objects.PM.PMQuote> GeneraPDF;

[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "PDF")]
protected void generaPDF()
{  

const string reportID = "XP995100";

var parameters = new Dictionary<string, string> { };
parameters.Add(nameof(PMQuote) + "." + nameof(PMQuote.QuoteProjectCD), Base.Quote.Current.QuoteProjectCD);
byte[] byteArray = GetPDFDocumentFromReport(parameters, reportID);
PX.SM.UploadFileMaintenance upl = PXGraph.CreateInstance<PX.SM.UploadFileMaintenance>();
PX.SM.FileInfo fileinfo = new PX.SM.FileInfo($"{Base.Quote.Current.QuoteNbr}.pdf", null, byteArray);
if (upl.SaveFile(fileinfo, PX.SM.FileExistsAction.CreateVersion))
{
    PXNoteAttribute.SetFileNotes(Base.Quote.Cache, Base.Quote.Current, fileinfo.UID.Value);
    this.Base.Save.Press();
}

}

#region InjectDependency

[InjectDependency]
protected IReportLoaderService ReportLoader { get; private set; }

[InjectDependency]
protected IReportDataBinder ReportDataBinder { get; private set; }
#endregion
public virtual byte[] GetPDFDocumentFromReport(Dictionary<string, string> parameters, string reportID)
{
    Report _report = ReportLoader.LoadReport(reportID, null);
    ReportLoader.InitReportParameters(_report, parameters, new PXReportSettings());
    ReportNode reportNode = ReportDataBinder.ProcessReportDataBinding(_report);
    //Generation PDF
    byte[] data = PX.Reports.Mail.Message.GenerateReport(reportNode, RenderType.FilterPdf).First();
    return data;
}

 

Images, Running from the same Report screen.

 

My English is a little bad, I hope I have been clear with the question, if anyone knows what I am doing wrong, they would be kind to tell me, thank you very much.

1 reply

Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3409 replies
  • August 25, 2024

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings