Skip to main content
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, e.g. separating an alpha code (a three-letter currency code) from a currency amount specified in the document.
  • Choosing one of several field values, e.g. 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. To set up a Script activity, follow the steps below:
  1. 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. In the Activity Properties pane, click Script Editor.
  3. In the dialog that will open, 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. Below are some sample script rules that you can use.

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;
}
  1. Once your script is ready, click Save. Doing so will display a list in the Activity Properties pane containing all fields used in the script. Verify that the list contains all required fields.
  2. Test your skill by clicking Test Activity and analyzing 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.