You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Acumatica中执行导出场景并获取输出文件(附问题代码)

在Acumatica中执行导出场景并获取输出文件

问题分析

你的代码核心逻辑方向正确,但在调用GetLatestFile.Press()时缺少必要的适配器参数,且没有对返回的文件对象做处理,导致无法获取到输出文件。

修复后的代码

SYExportProcessSingle exportGraph = PXGraph.CreateInstance<SYExportProcessSingle>();
SYMapping mapping = new PXSelect<SYMapping, Where<SYMapping.name, Equal<Required<SYMapping.name>>>>(exportGraph).SelectSingle(scenarioName);

if (mapping != null)
{
    // 定位目标导出场景
    exportGraph.MappingsSingle.Current = exportGraph.MappingsSingle.Search<SYMapping.name>(scenarioName);
    
    // 执行准备操作并等待完成
    exportGraph.Prepare.Press();
    PXLongOperation.WaitCompletion(exportGraph.UID);
    
    // 执行导出操作并等待完成
    exportGraph.Export.Press();
    PXLongOperation.WaitCompletion(exportGraph.UID);
    
    // 重新定位场景,确保上下文状态正确
    exportGraph.MappingsSingle.Current = exportGraph.MappingsSingle.Search<SYMapping.name>(scenarioName);
    
    // 通过PXAdapter调用GetLatestFile,获取文件结果
    PXAdapter adapter = new PXAdapter(exportGraph.MappingsSingle);
    var fileResults = exportGraph.GetLatestFile.Press(adapter);
    
    // 处理获取到的文件
    if (fileResults != null && fileResults.Count > 0)
    {
        PX.SM.FileInfo exportFile = fileResults[0] as PX.SM.FileInfo;
        if (exportFile != null)
        {
            // 访问文件内容与名称,可根据需求处理(如保存到本地、读取字节流)
            byte[] fileContent = exportFile.FileData;
            string fileName = exportFile.FileName;
            // 示例:保存到本地路径
            // File.WriteAllBytes(@"C:\AcumaticaExports\" + fileName, fileContent);
        }
    }
}

关键修复说明

  • 调用GetLatestFile.Press()必须传入PXAdapter,否则无法正确返回文件对象
  • 每次长操作后通过PXLongOperation.WaitCompletion确保流程执行完毕,避免上下文状态混乱
  • 新增文件对象处理逻辑,直接通过PX.SM.FileInfo访问导出文件的内容和名称

内容的提问来源于stack exchange,提问作者user3708398

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.21 04:15:50