메인 콘텐츠로 건너뛰기
다음은 실제 시나리오에서 사용할 수 있는 몇 가지 샘플 스크립트입니다.

문서의 규칙 오류 확인하기

아래 스크립트는 트랜잭션에 포함된 문서들에 규칙 오류가 있는지 확인합니다. 하나 이상의 문서에 규칙 오류가 있으면 스크립트는 true를 반환하고, 그렇지 않으면 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();

수동 검토가 필요한지 확인하기

다음 스크립트는 트랜잭션 문서에 오류가 있는지 확인합니다. 하나 이상의 트랜잭션 문서에 다음 항목 중 하나라도 해당하면:
  • 규칙 오류
  • 문서 유형이 불확실함
  • 인식 결과가 불확실한 field 또는 field 문자
스크립트는 true를 반환하고 문서를 수동 검토 단계로 보냅니다. 그렇지 않으면 스크립트는 false를 반환하고 문서를 내보내기 단계로 보냅니다.
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) {
    // 규칙 오류 존재
    if (document.RuleErrors.length > 0)
        return true;
    // 문서 유형 신뢰도 낮음
    if (!document.IsResultClassConfident)
        return true;
    // 일부 field가 의심스러움
    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) {
    // 모든 하위 항목에서 의심스러운 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;
        }
    }
    // 모든 인스턴스에서 의심스러운 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();