简体   繁体   English

通过Acumatica REST API从at获取PDF格式的报告输出

[英]Get report output in PDF fromat via Acumatica REST API

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 ? 通过REST API为特定屏幕调用操作后,是否可以获得生成报告的PDF输出?

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 . 例如,我们希望为外部应用程序的用户提供在Acumatica的“ AR发票”屏幕中针对特定发票执行“打印发票/备忘录表格”操作的功能。 They expect to get Invoice Form in PDF format as the result of the call. 他们希望通过电话获得PDF格式的发票表格。

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. Acumatica登录信息和报告参数值存储在外部应用程序中。

Thank you! 谢谢!

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. 首先在“ 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();
    }
}

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. 其次,您将必须使用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[];
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM