JS

Contents

JS (Java Script) allows to use of Java Script scripting language inside Scanshare scripting.

The scripts are executed natively at 64bits hence the script can use up to the maximum amount of RAM available on system.

Warning

Scripts are executed inside a Windows service hence interactive objects are strictly forbidden and if used they will cause the script to hang inside the no User desktop session of a Windows service.

Info

Based on the context where the script is used it may have different syntax and may require specific return values.

No pre-requirements are needed for JS scripting and no Java is required to run JS scripts.

JS supports all Javascript standards with the limitation of not running in a client side (e.g. browsers) environment, especially when referring to file inclusions and access rights.

JS script compliance respects full ECMA 5.1 compliance with partially ECMA 6.0 implementation, full base CLR namespace and classes with support for objects, properties, methods, delegates and anonymous objects.

When using native data CLR data types they need to be converted to the appropriate and corresponded JS native data types. Follow this conversion table for data type conversion JS->CLR:

JSCLR
Object expando objects (IDictionary and dynamic)
Arrayobject[]
Date DateTime
numberdouble
string string
boolean bool
Regexp RegExp
Function Delegate

In case of errors they will be logged in the process logs with details of the error.

No debugging is supported because JS code is running in a context of a Windows Service where interactive actions are not allowed and break points can produce unexpected general behaviors.

Furthermore no threading is supported because Scanshare processing engine is a synchronous FIFO queue and async operations are not handled while the processing engine waits for the script execution to proceed to the next workflow step.

Script 1

This script will store all folders in the root of the c: drive in” Results”, separated by semicolons.

var folders = System.IO.Directory.GetDirectories("C:\\");

RESULT = System.String.Join(";", folders);

Script 2

This script will parse a CSV file on the disk to look for a correspondent value obtained from a variable called MY_VARIABLE (for example a question). If found it will return in “Results” the next comma separated value.

var csvPath = "SUPPLIERS_NEW.txt";
var variable = Metadata.Values("MY_VARIABLE");
var csvText = System.IO.File.ReadAllLines(csvPath);

Metadata.SetValues("MY_VARIABLE_FROM_CSV", "## NOT FOUND ##");

for (var i=0; i<csvText.length; i++) {
  var items = csvText[i].split(",");
  if(items[0] == variable)
    Metadata.SetValues("MY_VARIABLE_FROM_CSV", items[1]);
}
Previous Article

VBS

Next Article

Variables