Skip to main content
Common patterns for writing a Condition activity script. Each sample reads from Context.Transaction.Documents 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.
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.
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();