Page tree
Skip to end of metadata
Go to start of metadata

Overview

The RunScriptOnDocument  component lets us manipulate field values in an IngestDocument  by using Javascript instead of the Java Server API.  It is intended as a convenience for developers who have more .NET experience than Java experience.


This feature runs any JSR-223 compatible scripting language as a document transformer.  It is expected to return a ProcessingResultCode  or the string equivalent of such a code. 


View incoming links.

Create RunScriptOnDocument Component


RunScriptOnDocument  is a standard document transformer that can be used to create workflow components in the AIE Administrator.


In the AIE Administrator, navigate to the System Management > Palette screen. Click New, which exposes the Select a Platform Component Type dialog.  Type "runScriptOnDocument" in the Filter field and click the button.  Select runScriptOnDocument from the resulting list and click OK to open a component editor.

Name the component. We called it myRunScriptOnDocument.

Paste in a Javascript script, or supply the path and filename that leads to the script. (See next section.) Slick Save.

Note that this creates a dynamic change in the project.  The component will be immediately functional, but you'll have to update the project using AIE-CLI.exe before the changes become permanent. 

Create the Script

The script will be run against every IngestDocument that reaches the component.  Two variables are pre-bound when the script runs:

  • doc - The doc variable is bound to the current IngestDocument

    . The document's methods are available in the script. For instance, doc.getId--  can be used to acquire the document's ID.


  • log - The log variable is bound to the current AttivioLogger

    .  The logger's methods are available in the script.  For instance, log.info--  can be used to send an info-level log message. 


In addition, the script is expected to return a ProcessingResultCode  or the string equivalent of such a code: 


PRCInterpretation
COMPLETED
Indicates that a message reached the end of it's workflow.
DROP
Successfully processed the message, but did not pass it on to the next stage.
FAIL
Document failed.
NOT HANDLED
Not handled by this component.
OK
Successfully processed the message.
WARN
Indicates that a stage had a warning about a document but did not fail the document.

The example script below operates on the title field of documents. If there is a title field and a country field, it appends the value of the country field to the title field.  Used on Factook city data, it changes "Beijing" into "Beijing, China". Then it logs the event as an info-level message, and returns the code 'OK'. 

if (doc.containsFieldValue('title')) 
  {
   var newTitle =   doc.getFirstValueAsString('title');
   if (doc.containsFieldValue('country'))
      { newTitle = newTitle +', '+ doc.getFirstValueAsString('country'); 
         doc.setField('title', newTitle ); 
         log.info("Changed title of " + doc.getId());
      }
  }
  'OK';

Just paste the script into the component editor and save it.

Debugging the Script

If the script contains errors, they will be posted to the server log file.  There are two ways to view these messages:

  • Open the log file in a text editor.  Look for it in <data-agent>\projects\<project-name>\<environment-name>\logs\logs-<node-name>\aie-node.log.
  • View the file in AIE Administrator.  Navigate to System Management > Logging > Log Viewer.

Insert myRunScriptOnDocument in a Workflow

It is not enough to create the component.  The component must then be inserted in an appropriate workflow.  In this case, we placed the myRunScriptOnDocument component as the next-to-last component of the ingest workflow.

In the AIE Administrator, navigate to System Management > Workflows > Ingest > ingest to open the ingest workflow editor.  Add myRunScriptOnDocument to the workflow, and put it in the next-to-final position.  Save the workflow.

Example Run

Configure the myRunScriptOnDocument component as shown above in a FactBook demo (see the Quick Start Tutorial for instructions.)

For a clean example, load the cities feed only.

In AIE Administrator, navigate to System Management > Query > SAIL.  Execute any search that pulls up city records.  Look at the titles.  If the title consists of a city name followed by a country name, then the script has executed correctly.

 

 

 

  • No labels