【问题标题】:Exporting Records from Acumatica via Screen-Based API通过基于屏幕的 API 从 Acumatica 导出记录
【发布时间】:2018-03-03 08:39:46
【问题描述】:

本主题将演示如何通过基于屏幕的 API 从 Acumatica ERP 导出记录。 Acumatica ERP 的 Screen-Based API 仅提供 SOAP 接口。如果您的开发平台对 SOAP Web 服务的支持有限,请考虑提供 SOAP 和 REST 接口的基于合同的 API。有关基于屏幕的 API 的更多信息,请参阅Acumatica ERP Documentation

【问题讨论】:

    标签: soap acumatica acumatica-kb


    【解决方案1】:

    从具有单个主键的条目表单中导出数据

    库存项目 屏幕 (IN.20.25.00) 是 Acumatica ERP 用于导出数据的最常用的数据输入形式之一。 Inventory IDStock Items 屏幕上的唯一主键:

    要从数据输入表单中导出记录,您的 SOAP 请求必须始终以 ServiceCommands.Every[Key] 命令开头,其中 [Key] 将替换为主键名称。

    在单个 Web 服务调用中导出所有库存项目:

    Screen context = new Screen();
    context.CookieContainer = new System.Net.CookieContainer();
    context.Url = "http://localhost/AcumaticaERP/Soap/IN202500.asmx";
    context.Login(username, password);
    try
    {
        Content stockItemsSchema = PX.Soap.Helper.GetSchema<Content>(context);
        Field lastModifiedField = new Field
        {
            ObjectName = stockItemsSchema.StockItemSummary.InventoryID.ObjectName,
            FieldName = "LastModifiedDateTime"
        };
        var commands = new Command[]
        {
            stockItemsSchema.StockItemSummary.ServiceCommands.EveryInventoryID,
            stockItemsSchema.StockItemSummary.InventoryID,
            stockItemsSchema.StockItemSummary.Description,
            stockItemsSchema.GeneralSettingsItemDefaults.ItemClass,
            stockItemsSchema.GeneralSettingsUnitOfMeasureBaseUnit.BaseUnit,
            lastModifiedField
        };
        var items = context.Export(commands, null, 0, false, false);
    }
    finally
    {
        context.Logout();
    }
    

    随着时间的推移,任何 ERP 应用程序中的数据量都趋于增长。如果您将在单个 Web 服务调用中从 Acumatica ERP 实例中导出所有记录,很快您可能会注意到超时错误。增加超时可能是一次性的,但不是很好的长期解决方案。应对这一挑战的最佳选择是分批导出多条记录的库存项目。

    以 10 条记录为单位批量导出库存商品:

    Screen context = new Screen();
    context.CookieContainer = new System.Net.CookieContainer();
    context.Url = "http://localhost/AcumaticaERP/Soap/IN202500.asmx";
    context.Login(username, password);
    try
    {
        Content stockItemsSchema = PX.Soap.Helper.GetSchema<Content>(context);
        Field lastModifiedField = new Field
        {
            ObjectName = stockItemsSchema.StockItemSummary.InventoryID.ObjectName,
            FieldName = "LastModifiedDateTime"
        };
        var commands = new Command[]
        {
            stockItemsSchema.StockItemSummary.ServiceCommands.EveryInventoryID,
            stockItemsSchema.StockItemSummary.InventoryID,
            stockItemsSchema.StockItemSummary.Description,
            stockItemsSchema.GeneralSettingsItemDefaults.ItemClass,
            stockItemsSchema.GeneralSettingsUnitOfMeasureBaseUnit.BaseUnit,
            lastModifiedField
        };
        var items = context.Export(commands, null, 10, false, false);
    
        while (items.Length == 10)
        {
            var filters = new Filter[]
            {
                new Filter
                {
                    Field = stockItemsSchema.StockItemSummary.InventoryID,
                    Condition = FilterCondition.Greater,
                    Value = items[items.Length - 1][0]
                }
            };
            items = context.Export(commands, filters, 10, false, false);
        }
    }
    finally
    {
        context.Logout();
    }
    

    单调用方式和批量导出主要有2个区别:

    • topCount 在单次调用方法中,Export 命令的参数始终设置为0

    • 批量导出记录时,通过topCount参数配置批量大小,辅以Filter数组请求下一个结果集

    从具有复合主键的条目表单中导出数据

    销售订单屏幕 (SO.30.10.00) 是具有复合主键的数据输入表单的完美示例。 销售订单界面的主键由订单类型订单号组成:

    通过基于屏幕的 API 从 销售订单 屏幕或任何其他具有复合主键的数据输入表单导出数据的推荐两步策略:

    • 在第 1 步中,您请求之前在 Acumatica ERP 应用程序中创建的所有类型的订单

    • 第二步是在单个调用或批量中独立导出每种类型的订单

    请求所有类型的现有订单:

    Screen context = new Screen();
    context.CookieContainer = new System.Net.CookieContainer();
    context.Url = "http://localhost/AcumaticaERP/Soap/SO301000.asmx";
    context.Login(username, password);
    try
    {
        Content orderSchema = PX.Soap.Helper.GetSchema<Content>(context);
        var commands = new Command[]
        {
            orderSchema.OrderSummary.ServiceCommands.EveryOrderType,
            orderSchema.OrderSummary.OrderType,
        };
    
        var types = context.Export(commands, null, 1, false, false);
    }
    finally
    {
        context.Logout();
    }
    

    在上面的 SOAP 调用中,注意 Export 命令的 topCount 参数设置为 1。此请求的目的只是获取之前在您的 Acumatica ERP 应用程序中创建的所有类型的订单,而不是导出数据。

    分批独立导出每种类型的记录:

    Screen context = new Screen();
    context.CookieContainer = new System.Net.CookieContainer();
    context.Url = "http://localhost/AcumaticaERP/Soap/SO301000.asmx";
    context.Login(username, password);
    try
    {
        Content orderSchema = PX.Soap.Helper.GetSchema<Content>(context);
        var commands = new Command[]
        {
            orderSchema.OrderSummary.ServiceCommands.EveryOrderType,
            orderSchema.OrderSummary.OrderType,
        };
        var types = context.Export(commands, null, 1, false, false);
    
        for (int i = 0; i < types.Length; i++)
        {
            commands = new Command[]
            {
                new Value
                {
                    LinkedCommand = orderSchema.OrderSummary.OrderType,
                    Value = types[i][0]
                },
                orderSchema.OrderSummary.ServiceCommands.EveryOrderNbr,
                orderSchema.OrderSummary.OrderType,
                orderSchema.OrderSummary.OrderNbr,
                orderSchema.OrderSummary.Customer,
                orderSchema.OrderSummary.CustomerOrder,
                orderSchema.OrderSummary.Date,
                orderSchema.OrderSummary.OrderedQty,
                orderSchema.OrderSummary.OrderTotal
            };
            var orders = context.Export(commands, null, 100, false, false);
            while (orders.Length == 100)
            {
                var filters = new Filter[]
                {
                    new Filter
                    {
                        Field = orderSchema.OrderSummary.OrderNbr,
                        Condition = FilterCondition.Greater,
                        Value = orders[orders.Length - 1][1]
                    }
                };
                orders = context.Export(commands, filters, 100, false, false);
            }
        }
    }
    finally
    {
        context.Logout();
    }
    

    上面的示例演示了如何从 Acumatica ERP 中以 100 条记录为一组导出所有销售订单。要独立导出每种类型的销售订单,您的 SOAP 请求必须始终以 Value 命令开头,该命令确定要导出的订单类型。在用于设置第一个键值的 Value 命令之后执行ServiceCommands.Every[Key] 命令,其中[Key] 将替换为第二个键的名称。

    导出特定类型的记录:

    如果您需要导出特定类型的销售订单,可以在 SOAP 请求的开头使用Value 命令显式定义订单类型,然后使用单调用方法或批量导出。

    一键导出IN类型的所有销售订单:

    Screen context = new Screen();
    context.CookieContainer = new System.Net.CookieContainer();
    context.Url = "http://localhost/AcumaticaERP/Soap/SO301000.asmx";
    context.Login(username, password);
    try
    {
        Content orderSchema = PX.Soap.Helper.GetSchema<Content>(context);
        var commands = new Command[]
        {
            new Value
            {
                LinkedCommand = orderSchema.OrderSummary.OrderType,
                Value = "IN"
            },
            orderSchema.OrderSummary.ServiceCommands.EveryOrderNbr,
            orderSchema.OrderSummary.OrderType,
            orderSchema.OrderSummary.OrderNbr,
            orderSchema.OrderSummary.Customer,
            orderSchema.OrderSummary.CustomerOrder,
            orderSchema.OrderSummary.Date,
            orderSchema.OrderSummary.OrderedQty,
            orderSchema.OrderSummary.OrderTotal
        };
        var orders = context.Export(commands, null, 0, false, false);
    }
    finally
    {
        context.Logout();
    }
    

    【讨论】:

      猜你喜欢
      • 2018-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多