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: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.
- 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.
Set up a Script activity
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.
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.
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.
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.
- 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.
