acumatica Exporting Records via Screen-Based API Data Export from an Entry Form with a Single Primary Key


Example

The Stock Items screen (IN.20.25.00) is one of the most often used data entry forms of Acumatica ERP to export data. Inventory ID is the only primary key on the Stock Items screen: enter image description here

To export records from a data entry form, your SOAP request must always begin with the ServiceCommands.Every[Key] command, where [Key] is to be replaced with primary key name.

To export all stock items in a single web service call:

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();
}

With time amount of data in any ERP application tends to grow in size. If you will be exporting all records from your Acumatica ERP instance in a single web service call, very soon you might notice timeout errors. Increasing timeout is a possible one-time, but not very good long-term solution. Your best option to address this challenge is to export stock items in batches of several records.

To export stock items in batches of 10 records:

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();
}

There are 2 main differences between the single call approach and the export in batches:

  • topCount parameter of the Export command was always set to 0 in the single call approach

  • when exporting records in batches, size of a batch is configured though the topCount parameter supplemented by the Filter array to request the next result set