通过基于屏幕的方式从 Acumatica 导出记录 API
Exporting Records from Acumatica via Screen-Based API
本主题将演示如何通过基于屏幕的 API 从 Acumatica ERP 导出记录。 Acumatica ERP 的 Screen-Based API 仅提供 SOAP 接口。如果您的开发平台对 SOAP Web 服务的支持有限,请考虑同时提供 SOAP 和 REST 接口的 Contract-Based API。有关基于屏幕的 API 的更多信息,请参阅 Acumatica ERP Documentation
使用单个主键从条目表单导出数据
库存项目 屏幕 (IN.20.25.00) 是 Acumatica ERP 导出数据最常用的数据输入形式之一。 库存 ID 是 库存物品 屏幕上唯一的主键:
要从数据输入表单导出记录,您的 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();
}
单次调用和批量导出有两个主要区别:
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();
}
上面的示例演示了如何以 100 条记录为一组从 Acumatica ERP 导出所有销售订单。要单独导出每种类型的销售订单,您的 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();
}
本主题将演示如何通过基于屏幕的 API 从 Acumatica ERP 导出记录。 Acumatica ERP 的 Screen-Based API 仅提供 SOAP 接口。如果您的开发平台对 SOAP Web 服务的支持有限,请考虑同时提供 SOAP 和 REST 接口的 Contract-Based API。有关基于屏幕的 API 的更多信息,请参阅 Acumatica ERP Documentation
使用单个主键从条目表单导出数据
库存项目 屏幕 (IN.20.25.00) 是 Acumatica ERP 导出数据最常用的数据输入形式之一。 库存 ID 是 库存物品 屏幕上唯一的主键:
要从数据输入表单导出记录,您的 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();
}
单次调用和批量导出有两个主要区别:
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();
}
上面的示例演示了如何以 100 条记录为一组从 Acumatica ERP 导出所有销售订单。要单独导出每种类型的销售订单,您的 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();
}