【问题标题】:Add Files to Salesorder line item将文件添加到销售订单行项目
【发布时间】:2019-08-03 20:26:45
【问题描述】:

我想使用 Web 服务将文件添加到 Acumatica 中的销售订单行项目。 应该使用什么端点?

我想使用 Web 服务端点添加如上图所示的图像。

【问题讨论】:

  • 这是一篇展示 REST 示例的文章:asiablog.acumatica.com/2018/01/attach-files-with-rest-api.html
  • @Brendan 我已经检查过了,我想将文件添加到销售订单详细信息行项目。 http:/localhost/entity/Custom/1.2/SalesOrder/SO/076267//files/image.jpg 在中,Detail line item的值应该是多少
  • @HB_ACUMATICA 你能解释一下吗?
  • 还没写完,不小心发了评论。似乎只有基于屏幕的 Web 服务 API 可以将文件附加到详细信息行。我将发布基于屏幕的示例,因为这是我被告知唯一可以做到这一点的示例。

标签: acumatica


【解决方案1】:

REST API 需要引用正文中的详细信息行。由于正文用于传递附件 REST API 的二进制数据,因此不能用于将文件附加到详细信息行。

下面是一个基于屏幕的 API sn-p,它创建一个新的主/详细文档并将图像附加到详细信息行。如果您选择使用基于屏幕的 API,您将需要为销售订单 ASMX 屏幕调整 sn-p 并获取具有扩展详细信息 SOLine 的销售订单。附加文件的模式将是相同的:

string[] detailDescription = "Test";
List<string> filenames = "image.jpg";
List<byte[]> images = new byte[] { put_image_binary_data_here } ;

ServiceReference1.Screen context = new ServiceReference1.Screen();
context.CookieContainer = new System.Net.CookieContainer();
context.Url = "http://localhost/Demo/Soap/XYZ.asmx";
context.Login("admin@CompanyLoginName", "admin");

ServiceReference1.XY999999Content content = PX.Soap.Helper.GetSchema<ServiceReference1.XY999999Content>(context);

List<ServiceReference1.Command> cmds = new List<ServiceReference1.Command>
{
    // Insert Master
    new ServiceReference1.Value { Value="<NEW>", LinkedCommand = content.Document.KeyField},
    new ServiceReference1.Value { Value="Description", LinkedCommand = content.Document.Description},

    // Insert Detail
    content.DataView.ServiceCommands.NewRow,
        new ServiceReference1.Value { Value = noteDetail[0], LinkedCommand = content.DataView.Description },

    // Attaching a file to detail
    new ServiceReference1.Value
    {
        Value = Convert.ToBase64String(images[0]),
        FieldName = filenames[0],
        LinkedCommand = content.DataView.ServiceCommands.Attachment
    },
    content.Actions.Save,
    content.Document.KeyField
};

var returnValue = context.PP301001Submit(cmds.ToArray());
context.Logout();

【讨论】:

  • 如何使用基于屏幕的 API 将文件附加到 salesorder 详细信息项目?
  • I200 基于屏幕的 API 培训文档页面解释了第 94 页上的“更新销售订单的详细信息行”。您可以使用我的回答中的示例将文件附加到详细信息部分。 openuni.acumatica.com/courses/integration/…
【解决方案2】:

这是一个老问题,但我在协助客户进行第三方集成时遇到了同样的问题。第三方开发人员坚持认为他们只能使用 REST 服务,因为他们已经围绕它构建了其余的集成,然后才意识到他们无法将文件附加到销售订单行。

我能够使用自定义构建解决方法。手头的问题是 Acumatica 的 REST API 附加文件的方式只有顶级实体才能访问 - 这意味着必须有一个将对象用作主要 DAC 的屏幕。

解决方法就是这样做,创建一个使用 SOLine 对象作为主要 DAC 的新自定义屏幕。为了使选择器可用,我必须删除和替换关键字段上的几个属性,以便它们可见并启用。这是图形代码 - 它非常简单,因为这基本上只是能够创建使用 SOLine DAC 作为顶级实体的自定义端点所需的最低限度。

public class SOLineAttachmentEntry : PXGraph<SOLineAttachmentEntry, SOLine>
{
    public PXSelect<SOLine> SOLineDetail;
    
    [PXMergeAttributes(Method = MergeMethod.Append)]
    [PXRemoveBaseAttribute(typeof(PXUIFieldAttribute))]
    [PXUIField(DisplayName = "Order Type", Visible=true, Enabled = true)]
    protected virtual void SOLine_OrderType_CacheAttached(PXCache sender) { }
      
    [PXMergeAttributes(Method = MergeMethod.Append)]
    [PXRemoveBaseAttribute(typeof(PXUIFieldAttribute))]
    [PXUIField(DisplayName = "Order Nbr", Visible=true, Enabled = true)]
    protected virtual void SOLine_OrderNbr_CacheAttached(PXCache sender) { }
      
    [PXMergeAttributes(Method = MergeMethod.Append)]
    [PXRemoveBaseAttribute(typeof(PXUIFieldAttribute))]
    [PXRemoveBaseAttribute(typeof(PXLineNbrAttribute))]
    [PXUIField(DisplayName = "Line Nbr", Visible=true, Enabled = true)]
    protected virtual void SOLine_LineNbr_CacheAttached(PXCache sender) { }      

}

自定义屏幕布局应该是一个简单的表单,只有这三个关键字段:OrderType、OrderNbr、LineNbr。在自定义的屏幕编辑器中,您需要在每个字段的 Layout Properties 选项卡中设置 CommitChanges=true。

屏幕发布后,您可以使用它来创建新的自定义端点,并通过从自定义屏幕中选择 SOLine 视图来添加单个实体。我将端点命名为“SalesOrderDetailAttach”,将端点版本指定为 1.0,并将新实体命名为“SalesOrderDetail”。使用这些名称,文件附件请求应该是一个 PUT 请求,请求正文中包含二进制文件数据,使用 url 格式:

[AcumaticaBaseUrl]/entity/SalesOrderDetailAttach/1.0/SalesOrderDetail/[OrderType]/[OrderNbr]/[LineNbr]/files/[Desired filename in Acumatica]

这适用于这个非常特殊的情况,将文件附加到 SOLine 对象。屏幕和端点真的不应该用于其他任何事情,并且除了管理员和 API 用户之外的任何用户都不能访问自定义屏幕。最终,我建议使用另一个答案中的基于屏幕的方法,但如果使用 REST API 是绝对必须具备的,那么这是一种潜在的解决方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-01
    • 2013-06-07
    • 1970-01-01
    • 2014-12-26
    相关资源
    最近更新 更多