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

# Sample scripts

> Sample Condition activity scripts — common patterns for checking rule errors and routing documents to manual review.

Common patterns for writing a Condition activity script. Each sample reads from [`Context.Transaction.Documents`](/vantage/documentation/skill-designer/process/condition-activity/transaction) and returns a boolean.

## Checking for rule errors in a document

The script below returns `true` if at least one transaction document has rule errors, an undetermined document class, or suspicious symbols. Otherwise it returns `false`.

```javascript theme={null}
function hasRuleErrors() {
    for (var i = 0; i < Context.Transaction.Documents.length; i++) {
        var document = Context.Transaction.Documents[i];
        if (document.RuleErrors.length > 0 || document.IsUnknownSkill === true || document.HasSuspiciousSymbols === true)
            return true;
    }
    return false;
}
hasRuleErrors();
```

## Checking whether manual review is required

The following script returns `true` — routing documents to manual review — if at least one transaction document has any of:

* Rule errors
* An uncertain document type
* Suspicious fields or field characters (including nested children and repeating instances)

Otherwise it returns `false` and the documents continue to the export step.

```javascript theme={null}
function needManualReview() {
    for (var i = 0; i < Context.Transaction.Documents.length; i++) {
        var document = Context.Transaction.Documents[i];
        if (needManualReviewForDocument(document))
            return true;
    }
    return false;
}

function needManualReviewForDocument(document) {
    // Rule errors exist
    if (document.RuleErrors.length > 0)
        return true;
    // Document type is not confident
    if (!document.IsResultClassConfident)
        return true;
    // Some fields are suspicious
    for (var i = 0; i < document.Fields.length; i++) {
        var field = document.Fields[i];
        if (field.IsSuspicious || containSuspiciousFields(field))
            return true;
    }
    return false;
}

function containSuspiciousFields(field) {
    // Check all children for suspicious field
    if (field.Children) {
        for (var i = 0; i < field.Children.length; i++) {
            var childField = field.Children[i];
            if (childField.IsSuspicious || containSuspiciousFields(childField))
                return true;
        }
    }
    // Check all instances for suspicious field
    if (field.Instances) {
        for (var i = 0; i < field.Instances.length; i++) {
            var instanceField = field.Instances[i];
            if (instanceField.IsSuspicious || containSuspiciousFields(instanceField))
                return true;
        }
    }

    return false;
}
needManualReview();
```

## Related topics

<CardGroup cols={3}>
  <Card title="Context" icon="braces" href="/vantage/documentation/skill-designer/process/condition-activity/context">
    Global object exposing the current transaction, document, and processing.
  </Card>

  <Card title="Transaction" icon="exchange" href="/vantage/documentation/skill-designer/process/condition-activity/transaction">
    The current processing transaction and its documents.
  </Card>

  <Card title="Document" icon="file-lines" href="/vantage/documentation/skill-designer/process/condition-activity/document">
    The document being processed by the Condition activity.
  </Card>

  <Card title="Field" icon="font" href="/vantage/documentation/skill-designer/process/condition-activity/field">
    Properties for reading a document field's value, type, and OCR metadata.
  </Card>

  <Card title="RuleError" icon="triangle-exclamation" href="/vantage/documentation/skill-designer/process/condition-activity/rule-error">
    A Document skill validation rule error raised against a document.
  </Card>

  <Card title="Object model" icon="diagram-project" href="/vantage/documentation/skill-designer/process/condition-activity/object-model">
    Full JavaScript object reference for Condition activity scripts.
  </Card>
</CardGroup>
