Skip to main content
The script in this example is used to assemble documents into document sets defined by a Document Set Definition. The Document Set Definition contains a section named Borrower’s form and references to the following Document Definitions:
  • Passport
  • Guarantor’s documents
  • Co-borrower’s documents
  • Employer reference
The Borrower’s form section includes the following fields:
  • Co-borrower’s name
  • Loan sum
The documents that need to be included in the document set depend on the value of the Loan sum field. The script has two threshold values that determine which documents are included in the set:
  1. If the loan sum is less than the first threshold value, the document set only needs to contain a passport.
  2. If the loan sum is greater than the first threshold value but less than the second threshold value, the document set needs to contain a passport and an employer’s reference.
  3. If the loan sum is greater than the second threshold value, the document set needs to contain a passport, an employer’s reference and a guarantor’s documents.
In addition to this, if the Co-borrower’s name field contains a value, the document set needs to contain a co-borrower’s documents.The script below uses this logic to assembles document sets.
using System.Collections.Generic;
int creditSum = 0;
bool creditSumFound = false;
string cocreditor = "";
int formCount = 0;
string formName = "Borrower's form";
// Document Definitions used in the document set
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 ) {
// Find the form and determine the sum of the loan
    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++;
        }
    }
// Count the documents in the set
    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);
    }
}
// Check the number of sections and documents in the set
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);
// Check that the document set contains a co-borrower if a co-borrower name is present in the form
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);
// Check that the document set contains all of the document required due to the loan sum exceeding one of the thresholds
if (creditSumFound)
{
if (creditSum > 50000) // requires an employer reference
    {
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) // requires the guarantor's documents
    {
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);
    }
}
The script in this example works with the Identification Documents Document Set Definition. The Document Set Definition contains references to the following Document Definitions:
  • Passport
  • Driver’s license
Document sets produced by the script may only include one document of each of these types but at least one document of these types.The script below uses this logic to assemble document sets.
using System.Collections.Generic;
using System;
string docSetName = "Identification Documents";
int pagesCnt = 0;
// List of the types documents that may be included in the set
List<string> allowed = new List<string> {"Passport", "Driver's license"};
// Limit on the number of documents of each type in the set
List<int> allowedCount = new List<int>{1,1};
// The number of documents detected in the set
List<int> foundCount = new List<int>{0,0};
// Count the number of documents and pages in the set
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++;
}
// Check the number of documents and pages
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);