Get report output in PDF fromat via Acumatica REST API

我的未来我决定 提交于 2019-11-28 10:15:58

问题


Is it possible to get PDF output of the report generated as a result of the action invoked for the particular screen via REST API?

For instance, we want to provide users of the external application with the ability to execute "Print Invoice/Memo Form" action for a particular Invoice in the AR Invoice screen in Acumatica. They expect to get Invoice Form in PDF format as the result of the call.

If there is no such option, maybe there is a way to generate a link which will bring the user to the Invoice form report executed with the specified set of parameters values. Acumatica login information and report parameters values are stored in the external application.

Thank you!


回答1:


Short answer yes, long answer....not easily.

To implement the functionality you request the following steps must be taken.

First create an action on the AR Invoice screen that will generate a report, save and attach it to the document.

public class ARInvoiceEntryExtension : PXGraphExtension<ARInvoiceEntry>
{
    public PXAction<ARInvoice> exportReport;
    [PXUIField(DisplayName = "Export Report")]
    [PXButton]
    public virtual IEnumerable ExportReport(PXAdapter adapter)
    {
        //Report Paramenters
        Dictionary<String, String> parameters = new Dictionary<String, String>();
        parameters["ARInvoice.DocType"] = Base.Document.Current.DocType;
        parameters["ARInvoice.RefNbr"] = Base.Document.Current.RefNbr;

        //Report Processing
        PX.Reports.Controls.Report _report = PXReportTools.LoadReport("AR641000", null);
        PXReportTools.InitReportParameters(_report, parameters,
                SettingsProvider.Instance.Default);
        ReportNode reportNode = ReportProcessor.ProcessReport(_report);

        //Generation PDF
        byte[] data = PX.Reports.Mail.Message.GenerateReport(reportNode,
        ReportProcessor.FilterPdf).First();

        PX.SM.FileInfo file = new PX.SM.FileInfo(reportNode.ExportFileName + ".pdf", null, data);

        UploadFileMaintenance graph = new UploadFileMaintenance();
        graph.SaveFile(file);
        PXNoteAttribute.AttachFile(Base.Document.Cache, Base.Document.Current, file);

        return adapter.Get();
    }
}

Second you will have to create a method utilizing the Contract API to find the Invoice, trigger the action and then retrieve the file attached to the document.

class Program
{
    static void Main(string[] args)
    {
        AcumaticaProcessor processor = new AcumaticaProcessor();
        processor.Login();
        File[] result = processor.RetrieveReport("Invoice", "001007");
    }
}

public class AcumaticaProcessor
{
    DefaultSoapClient client = new DefaultSoapClient();

    public void Login()
    {
        client.Login("Username", "Password", "Company", "Branch", null);
    }

    public File[] RetrieveReport(string docType, string refNbr)
    {
        ARInvoice invoiceToFind = new ARInvoice()
        {
            Type = new StringSearch() { Value = docType },
            ReferenceNbr = new StringSearch() { Value = refNbr }
        };
        invoiceToFind = client.Get(invoiceToFind) as ARInvoice;

        InvokeResult result = client.Invoke(invoiceToFind, new ExportReport());


        return client.GetFiles(invoiceToFind) as File[];
    }
}


来源:https://stackoverflow.com/questions/49319158/get-report-output-in-pdf-fromat-via-acumatica-rest-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!