Skip to main content

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.

The Script activity is designed for implementing script rules in a skill aside from rules available in various extraction activities. A script can contain rules for processing or correcting data extracted by other activities. You may need to use script rules when doing the following:
  • Normalizing a field value, for example, separating an alpha code (a three-letter currency code) from a currency amount specified in the document.
  • Choosing one of several field values, for example, specifying which of several values should be selected and recorded in the result field if the value of a single field is extracted by more than one activity.
  • Calculating values of fields that could not be found in the document, e.g. calculating payable tax using a known tax rate when all fields with taxable amounts have been extracted.
Unlike business rules, script rules do not highlight values that contain errors during manual review. This is because script rules are designed to complement and correct various data obtained when processing documents, and are an integral part of Document skills.

Set up a Script activity

1

Add the activity

Add a Script activity to the document processing flow in the Activities tab. Note that you should add the activity after any other field extraction activities that your rule may contain.
2

Open the Script Editor

In the Activity Properties pane, click Script Editor.
3

Write the script

In the dialog that opens, set up your rule in script form by using JavaScript to create a script that carries out all required actions. You can use the quick edit buttons in the upper part of the screen to add preset code snippets to your script. For sample script rules you can adapt, see Sample script rules below.
4

Save the script

Click Save. The Activity Properties pane then displays a list of all fields used in the script. Verify that the list contains all required fields.
5

Test the activity

Click Test Activity and analyze the extraction results. If the rule did not work as intended, check that the script has been written correctly. Additionally, check the extraction quality of all fields used in the script rule.

Sample script rules

  • This script rule is designed to add a three-letter currency code to the value in the Total field. The rule first checks the value of the Country field. If the value of that field is either “USA” or “United States”, a “USD” code is added to the numeric value in the Total field. If the value of the Country field is either “United Kingdom” or “Great Britain”, a “GBP” code is added to the numeric value in the Total field.
if ( Context.GetField("Country").Value == "USA"|"United States" ) {
               Context.GetField("Total").Value = Context.GetField("Total").Value + " USD";
} else 
if( Context.GetField("Country").Value == "United Kingdom"|"Great Britain" ) {
               Context.GetField("Total").Value = Context.GetField("Total").Value + " GBP";
}
  • This script rule is designed to add the names of selected organizations to specified fields. The Preamble Org repeating field contains the names of all organizations listed in a document preamble, which are extracted by the Named Entities (NER) activity. The script rule is set up so that if the Preamble Org field contains the names of more than two organizations, the first extracted value will be placed in the Party 1 field, while the last will be placed in the Party 2 field.
var preambleOrgsFields = Context.GetFields("Preamble Org");
 
if (preambleOrgsFields.length > 2)
{
   Context.GetField("Party 1").Value = preambleOrgsFields[1].Value;
   Context.GetField("Party 2").Value = preambleOrgsFields[preambleOrgsFields.length - 1].Value;
}