> ## Documentation Index
> Fetch the complete documentation index at: https://docs.abbyy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# IBatchItems

> IBatchItems is a collection of IBatchItem elements with a Move method for reordering documents and pages, including a sample set-assembly script.

## What it is

A collection of [IBatchItem](/flexi-capture/appendix/scripts/i-batch-item).

<Note>
  This object is not available on the Web Verification Station for checking rules locally.
</Note>

## Methods

<table width="100%"><thead><tr><th style={{textAlign: 'left'}}><p><strong>Definition</strong></p></th><th style={{textAlign: 'left'}}><p><strong>Description</strong></p></th></tr></thead><tbody><tr><td><p>Move(item : <a href="/flexi-capture/appendix/scripts/i-batch-item">IBatchItem</a>, position : int)</p></td><td><p>Moves the element to the specified position in the collection.</p><p><strong>Note: </strong> Call this method on the collection where the element needs to be moved.</p><p><strong>Note: </strong> The <code>position</code> parameter may take values starting from 0 and up to the size of the collection.</p></td></tr></tbody></table>

## Properties

| **Name** | **Type** | **Access** | **Description**                          |
| -------- | -------- | ---------- | ---------------------------------------- |
| Count    | int      | Read-only  | The number of elements in the collection |

## Example of the Move method

This script runs several consecutive scenarios to assemble sets from unsorted lists of documents:

* Disassembles sets
* Groups documents by type in the specified order
* Groups documents by the specified key field
* Assembles documents into sets with the same key field

```csharp theme={null}
using System.Collections.Generic;
IBatchItems batch = Batch.AsBatchItem.ChildItems;
List<string> docDefs = new List<string> {"DocSet","Doc1","Doc2"}; // Document assembly order
// Key field name
// (the field should be indexed in all documents and have the same name)
string keyFieldName = "SSN";
List<string> keyFields = new List<string>();
// Disassembling sets
bool foundChildren = false;
do
{
    foreach (IBatchItem itm in batch)
    {
        if (itm.ChildItems.Count > 1)
        {
            int shift = 0;
            foreach (IBatchItem subItm in itm.ChildItems)
            {
                shift++;
                batch.Move(subItm, itm.Index + shift);
            }
        }
    }
    foreach (IBatchItem itm in batch)
        if (itm.ChildItems.Count > 1)
            foundChildren = true;
} while (foundChildren);
// Sorting documents the way they should be in the set
// (i.e. the set itself followed by all its subdocuments)
foreach (string docDefName in docDefs)
{
    List<int> indexList = new List<int>();
    foreach (IBatchItem itm in batch)
        if (itm.Type == TBatchItemType.BIT_Document)
            if (itm.AsDocument.DefinitionName == docDefName) indexList.Add(itm.Index);
    for (int i = 0; i < indexList.Count; i++)
        batch.Move(batch[indexList[i]-i], batch.Count);
}
// Searching for all options of key fields in the batch
foreach (IBatchItem itm in batch)
{
    if (itm.Type == TBatchItemType.BIT_Document)
    {
        string keyFieldValue = (string)itm.AsDocument.IndexedItemValue(keyFieldName);
        if (!keyFields.Contains(keyFieldValue))
            keyFields.Add(keyFieldValue);
    }
}
// Assembling documents with the same key field
foreach (string keyFieldValue in keyFields)
{
    List<int> indexList = new List<int>();
    foreach (IBatchItem itm in batch)
        if (itm.Type == TBatchItemType.BIT_Document)
            if ((string)itm.AsDocument.IndexedItemValue(keyFieldName) == keyFieldValue) indexList.Add(itm.Index);
    for (int i = 0; i < indexList.Count; i++)
        batch.Move(batch[indexList[i]-i], batch.Count);
}
// Moving subdocuments into sets only if key fields match
// (set sections first, child documents second)
int ind = 0;
while (ind < batch.Count)
{
    if (batch[ind].Type == TBatchItemType.BIT_Document)
        // Looking for the beginning of the set
        if (batch[ind].AsDocument.DefinitionName == docDefs[0])
            // If a document after the set is not a set and key fields match,
            // we add it to this set
            while (ind+1 < batch.Count &&
                   batch[ind+1].AsDocument.DefinitionName != docDefs[0] &&
                   (string)batch[ind+1].AsDocument.IndexedItemValue(keyFieldName) == (string)batch[ind].AsDocument.IndexedItemValue(keyFieldName))
                batch[ind].ChildItems.Move(batch[ind+1], batch[ind].ChildItems.Count);
    ind++;
}
```
