> ## 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.

# Beispielskripte zur Dokumentenzusammenstellung

> Beispielskripte zur Dokumentenzusammenstellung für ABBYY FlexiCapture-Dokumentensätze: Eines fügt auf Basis einer Darlehenssumme erforderliche Dokumente hinzu, ein anderes prüft, ob Dokumente fehlen.

Diese Beispielskripte stellen Dokumente zu Dokumentensätzen zusammen, die in einer Dokumentensatzdefinition definiert sind, und melden Probleme bei der Zusammenstellung über das Objekt `AssemblingErrors`. Im ersten Skript sind je nach Darlehenssumme unterschiedliche Dokumente erforderlich. Das zweite prüft, ob ein Satz die erwarteten Identifikationsdokumente enthält.

<div id="require-documents-based-on-the-loan-sum">
  ## Dokumente abhängig von der Darlehenssumme anfordern
</div>

Dieses Skript stellt Dokumente zu Dokumentensätzen zusammen, die in einer Dokumentensatzdefinition definiert sind. Die Dokumentensatzdefinition enthält eine Section mit dem Namen **Formular des Kreditnehmers** und Verweise auf die folgenden Dokumentdefinitionen:

* Reisepass
* Dokumente des Bürgen
* Dokumente des Mitantragstellers
* Arbeitgeberbestätigung

Die Section **Formular des Kreditnehmers** enthält die folgenden Felder:

* Name des Mitantragstellers
* Darlehenssumme

Welche Dokumente der Dokumentensatz enthalten muss, hängt vom Wert des Feldes **Darlehenssumme** ab. Das Skript verwendet zwei Schwellenwerte, um festzulegen, welche Dokumente erforderlich sind:

| Darlehenssumme                                                  | Erforderliche Dokumente                                         |
| --------------------------------------------------------------- | --------------------------------------------------------------- |
| Kleiner als der erste Schwellenwert                             | Reisepass                                                       |
| Größer als der erste Schwellenwert, aber kleiner als der zweite | Reisepass und eine Arbeitgeberbestätigung                       |
| Größer als der zweite Schwellenwert                             | Reisepass, eine Arbeitgeberbestätigung und Dokumente des Bürgen |

Wenn das Feld **Name des Mitantragstellers** einen Wert enthält, muss der Dokumentensatz auch Dokumente des Mitantragstellers enthalten.

Das folgende Skript verwendet diese Logik, um Dokumentensätze zusammenzustellen:

```csharp theme={null}
using System.Collections.Generic;
int creditSum = 0;
bool creditSumFound = false;
string cocreditor = "";
int formCount = 0;
string formName = "Borrower's form";
// Dokumentdefinitionen im Dokumentensatz
int referenceFromWorkCount = 0;
string referenceFromWorkName = "Employer reference";
int guaranteeDocsCount = 0;
string guaranteeDocsName = "Guarantor's documents";
int cocreditorDocsCount = 0;
string cocreditorDocsName = "Co-borrower's documents";
int passportCount = 0;
string passportName = "Passport";
foreach( IBatchItem item in BatchItems ) {
    // Formular suchen und Kreditsumme ermitteln
    if (item.Type == TBatchItemType.BIT_Page)
    {
        if (item.AsPage.SectionName != formName)
            AssemblingErrors.AddCustomError("Cannot contain the following sections: " + item.AsPage.SectionName, 1);
        else
        {
            cocreditor = item.AsPage.Document.IndexedItemValue("Borrower's name").ToString();
            string creditSumText = item.AsPage.Document.IndexedItemValue("Loan sum").ToString();
            if (!int.TryParse(creditSumText, out creditSum))
                AssemblingErrors.AddCustomError("Loan sum was not recognized: " + creditSumText, 1);
            else
                creditSumFound = true;
            formCount++;
        }
    }
    // Dokumente im Satz zählen
    else if (item.Type == TBatchItemType.BIT_Document) {
        if (item.AsDocument.TemplateName == referenceFromWorkName)
            referenceFromWorkCount++;
        else if (item.AsDocument.TemplateName == guaranteeDocsName)
            guaranteeDocsCount++;
        else if (item.AsDocument.TemplateName == passportName)
            passportCount++;
        else if (item.AsDocument.TemplateName == cocreditorDocsName)
            cocreditorDocsCount++;
        else
            AssemblingErrors.AddCustomError("The document set cannot contain the document " + item.AsDocument.TemplateName, 1);
    }
}
// Anzahl der Abschnitte und Dokumente im Satz prüfen
if (formCount > 1)
    AssemblingErrors.AddCustomError("There are too many documents of the type: " + formName, formCount);
else if (formCount < 1)
    AssemblingErrors.AddCustomError("Missing the following documents: " + formName, 1);
if (passportCount > 1)
    AssemblingErrors.AddCustomError("There are too many documents of the type: " + passportName, passportCount);
else if (passportCount < 1)
    AssemblingErrors.AddCustomError("Missing the following documents: " + passportName, 1);
// Prüfen, ob der Dokumentensatz einen Mitantragsteller enthält, wenn im Formular ein Mitantragstellername angegeben ist
if (cocreditor != "" && cocreditorDocsCount < 1)
    AssemblingErrors.AddCustomError("Missing the following documents: " + cocreditorDocsName, 1);
else if (cocreditor != "" && cocreditorDocsCount > 1)
    AssemblingErrors.AddCustomError("There are too many documents of the type: " + cocreditorDocsName, cocreditorDocsCount);
else if (cocreditor == "" && cocreditorDocsCount > 0)
    AssemblingErrors.AddCustomError("There are too many documents of the type: " + cocreditorDocsName, cocreditorDocsCount);
// Prüfen, ob der Dokumentensatz alle erforderlichen Dokumente enthält, weil die Kreditsumme einen der Schwellenwerte überschreitet
if (creditSumFound)
{
    if (creditSum > 50000) // erfordert eine Arbeitgeberauskunft
    {
        if (referenceFromWorkCount > 1)
            AssemblingErrors.AddCustomError("There are too many documents of the type: " + referenceFromWorkName, referenceFromWorkCount);
        else if (referenceFromWorkCount < 1)
            AssemblingErrors.AddCustomError("Missing the following documents: " + referenceFromWorkName, 1);
    }
    if (creditSum > 500000) // erfordert die Bürgschaftsdokumente
    {
        if (guaranteeDocsCount > 1)
            AssemblingErrors.AddCustomError("There are too many documents of the type: " + guaranteeDocsName, guaranteeDocsCount);
        else if (guaranteeDocsCount < 1)
            AssemblingErrors.AddCustomError("Missing the following documents: " + guaranteeDocsName, 1);
    }
}
```

<div id="check-for-missing-or-duplicate-documents">
  ## Auf fehlende oder doppelte Dokumente prüfen
</div>

Dieses Skript arbeitet mit der Dokumentensatzdefinition **Identification Documents**, die auf die folgenden Dokumentdefinitionen verweist:

* Reisepass
* Führerschein

Ein Dokumentensatz darf höchstens ein Dokument jedes Typs enthalten und muss mindestens eines dieser Dokumente umfassen.

Das folgende Skript verwendet diese Logik, um Dokumentensätze zusammenzustellen:

```csharp theme={null}
using System.Collections.Generic;
using System;
string docSetName = "Identification Documents";
int pagesCnt = 0;
// Liste der Dokumenttypen, die im Set enthalten sein dürfen
List<string> allowed = new List<string> {"Passport", "Driver's license"};
// Maximale Anzahl von Dokumenten jedes Typs im Set
List<int> allowedCount = new List<int>{1,1};
// Anzahl der im Set erkannten Dokumente
List<int> foundCount = new List<int>{0,0};
// Anzahl der Dokumente und Seiten im Set zählen
foreach (IBatchItem item in BatchItems) {
    if (item.Type == TBatchItemType.BIT_Document) {
        if (item.AsDocument.TemplateName == docSetName)
            AssemblingErrors.AddCustomError("Cannot contain a nested set", 1);
        else if (allowed.Contains(item.AsDocument.TemplateName)) {
            int i = allowed.IndexOf(item.AsDocument.TemplateName);
            foundCount[i]++;
        }
    }
    else if (item.Type == TBatchItemType.BIT_Page) pagesCnt++;
}
// Anzahl der Dokumente und Seiten prüfen
if (foundCount[0] + foundCount[1] == 0)
    AssemblingErrors.AddCustomError("At least one identification document is required", 1);
for (int i = 0; i < allowed.Count; i++) {
    if (foundCount[i] > allowedCount[i])
        AssemblingErrors.AddCustomError("Maximum number of documents: " + allowed[i] + ": " + allowedCount[i]);
}
if (pagesCnt > 0) AssemblingErrors.AddCustomError("The document set cannot contain pages that do not belong to a document", pagesCnt);
```
