【问题标题】:Get report output in PDF fromat via Acumatica REST API通过 Acumatica REST API 以 PDF 格式获取报告输出
【发布时间】:2018-08-25 10:15:14
【问题描述】:

是否可以通过REST API 为特定屏幕调用操作而生成报告的 PDF 输出?

例如,我们希望让外部应用程序的用户能够在 Acumatica 的 AR 发票屏幕中为特定发票执行“打印发票/备忘录表单”操作。他们希望通过电话获得 PDF 格式的发票表格。

如果没有这样的选项,也许有一种方法可以生成一个链接,将用户带到使用指定参数值集执行的发票表单报告。 Acumatica 登录信息和报告参数值存储在外部应用程序中。

谢谢!

【问题讨论】:

  • 仅供参考,据我所知,截至 2020 R2,这仍然无法使用基于合同的 REST API(无需自定义),但可以使用基于屏幕的 SOAP API。

标签: rest pdf acumatica


【解决方案1】:

短答案是的,长答案....不容易。

要实现您要求的功能,必须执行以下步骤。

首先在 AR 发票屏幕上创建一个操作,该操作将生成报告、保存并将其附加到文档中。

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();
    }
}

其次,您必须创建一个利用 Contract API 的方法来查找发票、触发操作,然后检索附加到文档的文件。

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[];
    }
}

【讨论】:

  • 你好约书亚。谢谢你的主意!似乎没有办法使用开箱即用的功能和端点来实现这一点。
  • 它需要扩展端点以添加自定义操作。这个方法不错。
猜你喜欢
  • 1970-01-01
  • 2018-12-18
  • 2017-11-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-24
相关资源
最近更新 更多