本主题将演示如何通过基于屏幕的API从Acumatica ERP导出记录。 Acumatica ERP的基于屏幕的API仅提供SOAP接口。如果您的开发平台对SOAP Web服务的支持有限,请考虑提供SOAP和REST接口的基于合同的API。有关基于屏幕的API的更多信息,请参阅Acumatica ERP Documentation
答案 0 :(得分:1)
Stock Items 屏幕(IN.20.25.00)是Acumatica ERP中用于导出数据的最常用数据输入形式之一。 广告资源ID 是 Stock Items 屏幕上唯一的主键:
要从数据输入表单导出记录,您的SOAP请求必须始终以ServiceCommands.Every[Key]
命令开头,其中[Key]
将替换为主键名称。
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实例中的所有记录,很快就会发现超时错误。增加超时可能是一次性但不是很好的长期解决方案。解决这一挑战的最佳选择是分批导出库存物品。
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 参数在单次调用方法中始终设置为0
批量导出记录时,通过 topCount 参数配置批量大小,并通过过滤器数组进行补充,以请求下一个结果集
销售订单屏幕(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调用中,请注意导出命令的 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();
}