代码之家  ›  专栏  ›  技术社区  ›  June B

我可以通过API删除Acumatica中的文件吗?

  •  0
  • June B  · 技术社区  · 6 年前

    我正在Acumatica中通过调用API中的操作创建一个文件,以便在应用程序中检索该文件。

    我处理完文件后,是否可以通过API删除该文件?我不希望它弄乱我的针灸数据库。

    2 回复  |  直到 6 年前
        1
  •  1
  •   June B    6 年前

    找到了如何从Acumatica中删除文件以及如何保存现有文件的新版本的示例!下面的实现保存了一个新版本,但删除方法已被注释掉。因为我将其构建到了报表生成过程中,所以我以后不会通过API删除报表,但很容易将删除转换为API可调用的操作。

    private IEnumerable ExportReport(PXAdapter adapter, string reportID, Dictionary<String, String> parameters)
        {
            //Press save if the SO is not completed 
            if (Base.Document.Current.Completed == false)
            {
                Base.Save.Press();
            }
    
            PX.SM.FileInfo file = null;
            using (Report report = PXReportTools.LoadReport(reportID, null))
            {
                if (report == null)
                {
                    throw new Exception("Unable to access Acumatica report writer for specified report : " + reportID);
                }
    
                PXReportTools.InitReportParameters(report, parameters, PXSettingProvider.Instance.Default);
                ReportNode reportNode = ReportProcessor.ProcessReport(report);
                IRenderFilter renderFilter = ReportProcessor.GetRenderer(ReportProcessor.FilterPdf);
    
                //Generate the PDF
                byte[] data = PX.Reports.Mail.Message.GenerateReport(reportNode, ReportProcessor.FilterPdf).First();
                file = new PX.SM.FileInfo(reportNode.ExportFileName + ".pdf", null, data);
    
                //Save the PDF to the SO
                UploadFileMaintenance graph = new UploadFileMaintenance();
    
                //Check to see if a file with this name already exists                
                Guid[] files = PXNoteAttribute.GetFileNotes(Base.Document.Cache, Base.Document.Current);
                foreach (Guid fileID in files)
                {
                    FileInfo existingFile = graph.GetFileWithNoData(fileID);
                    if (existingFile.Name == reportNode.ExportFileName + ".pdf")
                    {
                        //If we later decide we want to delete previous versions instead of saving them, this can be changed to 
                        //UploadFileMaintenance.DeleteFile(existingFile.UID);
                        //But in the meantime, for history purposes, set the UID of the new file to that of the existing file so we can save it as a new version.
                        file.UID = existingFile.UID;
                    }
                }
    
                //Save the file with the setting to create a new version if one already exists based on the UID                          
                graph.SaveFile(file, FileExistsAction.CreateVersion);  
                //Save the note attribute so we can find it again.              
                PXNoteAttribute.AttachFile(Base.Document.Cache, Base.Document.Current, file);
            }
    
            //Return the info on the file
            return adapter.Get();
        }
    
        2
  •  0
  •   June B    6 年前

    Acumatica的反应是: S-b(屏幕基础)API允许以干净的方式下载生成为文件的报告。C-b(合同基础)根本没有添加此功能。我建议您在这里提供反馈:feedback.acumatica.com(编辑:Done! https://feedback.acumatica.com/ideas/ACU-I-1852

    我认为有两种解决方法: 1) 使用从c-b登录的s-b生成报告并获取为文件(参见下面的示例),或者

    #1的示例

            using (DefaultSoapClient sc = new DefaultSoapClient("DefaultSoap1"))
            {
                string sharedCookie;
                using (new OperationContextScope(sc.InnerChannel))
                {
                    sc.Login("admin", "123", "Company", null, null);
                    var responseMessageProperty = (HttpResponseMessageProperty)
                    OperationContext.Current.IncomingMessageProperties[HttpResponseMessageProperty.Name];
                    sharedCookie = responseMessageProperty.Headers.Get("Set-Cookie");
                }
    
                try
                {
                    Screen scr = new Screen();  // add reference to report e.g. http://localhost/Demo2018R2/Soap/SO641010.asmx
                    scr.CookieContainer = new System.Net.CookieContainer();
                    scr.CookieContainer.SetCookies(new Uri(scr.Url), sharedCookie);
    
                    var schema = scr.GetSchema();
                    var commands = new Command[]
                    {
                        new Value { LinkedCommand = schema.Parameters.OrderType, Value = "SO" },
                        new Value { LinkedCommand = schema.Parameters.OrderNumber, Value = "SO004425" },
                        schema.ReportResults.PdfContent
                    };
    
                    var data = scr.Submit(commands);
                    if(data != null && data.Length > 0)
                    {
                        System.IO.File.WriteAllBytes(@"c:\Temp\SalesOrder.pdf", 
                            Convert.FromBase64String(data[0].ReportResults.PdfContent.Value));
                    }
                }
                finally
                {
                    sc.Logout();
                }
            } 
    

    纳扬·曼辛哈 首席开发人员支持| Acumatica