Getting Started With Scripts

A Script Rule allows you to send information to a custom script running on a remote agent.

To create a new script rule:

  1. On the Rules page, select the arrow beside New and select Script as your rule type.
  2. In the Create Script dialog box, specify the Name and Description for your rule, as well as the remote agent where your script will run.

    Note: Ensure that the selected remote agent contains a queue with the Remote Script Source Plugin.

  3. Click Create.
  4. In the Rule editor page, specify the location of the .dll/.py/.js file on the remote agent host (for example, "C:\ProcessAutomationWorker\bin\Script.dll"). For C# scripts, include the class name and the entry point name. If your C# class library contains multiple entry points, create another rule to access the additional entry points.

    Note: By default, scripts must be located within the bin subfolder within the remote agent worker installation folder (for example, C:\ProcessAutomationWorker\bin).

  5. Optional: Modify the plugin_settings.json file within the remote agent worker installation's bin subfolder to allow the worker to access additional paths on the remote agent computer. Append additional paths to the AllowList attribute in the RemoteScriptSourcePlugin block. For example, if you would like to open up access to the entire C:\ drive and a shared network path, you can update the attribute to "AllowList": [ "C:\\", "\\\\samplehost\\scriptsfolder" ]. If you have multiple remote agent workers, it is recommended that all scripts be located in a single directory accessible by all of the workers. The remote agent worker service user must still have appropriate Windows access rights to any specified paths. After the remote agent local configuration is modified, the remote agent service must be restarted for changes to take affect.
  6. Add any input or output parameters used.
  7. Test your script by clicking the Test Script button. The output values will be displayed in the Text box at the bottom of the page. If you do not have any outputs configured you will just get a generic success message. If your script performs actions on the remote agent host, please verify the expected output is available.
  8. Publish the rule to make it available for Workflow.
  9. Create a workflow and add a Run Script Rule activity to run your script. Select the rule created in the previous steps. Specify the input values with either static values or workflow tokens. The output values will be available as tokens in the rest of your workflow.

Tip: Visit the Laserfiche Git page to download blank script templates for your C#, Node.js, or Python scripts.

Creating a C# Script

This topic provides an overview on creating a sample C# script for use with a Laserfiche Cloud script rule.

  1. Within your Visual Studio class library project, you must include at least one entry point for Laserfiche Cloud that has the following signature:

    public static Task<IDictionary<string,object>> SampleMethodName(IDictionary<string,object> SampleInputName){…}

    Note: In the above example, "static" is optional, as the entry point may or may not be static.

    When running your script from a workflow, this entry point will be the method that is first called and the only method that can receive data from Laserfiche and return data to Laserfiche. Your class can contain additional methods that can act as additional entry points for Laserfiche. When configuring script rules, create additional rules to access the additional class methods.

    Any inputs you need from Laserfiche can be accessed by your script as items in the SampleInputName Dictionary, with the Dictionary key being the name of the configured input as defined in the script rule, and the Dictionary value being the runtime value of the input.

    Any outputs you need to return to Laserfiche should be stored in the returned Dictionary object, with the Dictionary key being the name of the configured output as defined in the script rule, and the Dictionary value being the runtime value of the output.

    The same method signature should be used even if your script does not require inputs and does not return an output.

  2. The following is an example of a Class Library that contains a function takes 2 input values and returns 2 output values to Laserfiche.
    					using System;
    					using System.Collections.Generic;
    					using System.Linq;
    					using System.Text;
    					using System.Threading.Tasks;
    
    					namespace ClassLibrary1
    					{
    					public class MyClass
    					{
    					//This is a method that takes inputs and returns outputs
    					//The names of the input and output parameters configured in the Rule are used as input and output Dictionary keys
    					public static Task<IDictionary<string, object>> MyScript(IDictionary<string, object> inputsFromRule) 
    					{
    					//Initialize a Dictionary to store your outputs
    					var outputsFromScript = new Dictionary<string, object>();
    
    					//Do all of your actions here
    					outputsFromScript["EchoInputs"] = inputsFromRule["firstInput"] + " " + inputsFromRule["secondInput"];
    					outputsFromScript["HelloWorld"] = "Hello World";
    
    					//Return your outputs as a Task result 
    					return Task.FromResult <IDictionary<string, object>> (outputsFromScript);
    					}
    					}
    					}
    			

Related Links

See the following Laserfiche Github page to download blank script templates for your C# scripts.

Note: If you do not use the Laserfiche script template, be sure that your Visual Studio script targets .Net 4.8.

Creating a Node.js Script

This topic provides an overview on creating a sample Node.js script for use with a Laserfiche Cloud Script Rule.

  1. Ensure that Node.js is installed on the remote agent host, and that the system variables have been configured to allow "node" or "node.exe" to run command-line Node.js scripts.
  2. Create a .js script file or use our helper script. Inputs in the script can be accessed by:

    process.argv[2] (…) process.argv[n+1]

    which will return the inputs to the script in the format:

    "inputName1=value1" (…) "inputNamen=valuen"

    which can be parsed in your script.

    Outputs from the script should be printed to the standard output in the format:

    "outputName1:value1"

  3. The following is an example of a Node.js script that takes two inputs, combines them, and returns them as a single output value.
  4. 				const process = require('process');
    				
    				let input1 = process.argv[2];
    				let idx1 = input1.indexOf('=');
    				let inputValue1 = input1.substring(idx1+1);
    				
    				let input2 = process.argv[3];
    				let idx2 = input2.indexOf('=');
    				let inputValue2 = input2.substring(idx2+1);
    				
    				var echoinput = function(z1,z2){
    				console.log("outputValue1:"+z1+" "+z2);
    				}
    				
    				echoinput(inputValue1, inputValue2);
    			

Related Links

See the following Laserfiche Github page to download blank script templates for your node.js scripts.

Creating a Python Script

This topic provides an overview on creating a sample Python script for use with a Laserfiche Cloud Script Rule.

  1. Ensure that Python is installed on the remote agent host, and that the system variables have been configured to allow "python" or "python.exe" to run command-line python scripts.
  2. Create a .py script file or use our helper script. Inputs in the script can be accessed by:

    sys.argv[1] (…) sys.argv[n]

    which will return the inputs to the script in the format:

    "inputName1=value1" (…) "inputNamen=valuen"

    which can be parsed in your script.

    Outputs from the script should be printed to the standard output in the format:

    "outputName1:value1"

  3. The following is an example of a Python script that takes two inputs, combines them, and returns them as a single output value.
  4. 				import sys
    				def main():
    				inputval1 = sys.argv[1].split("=")[1]
    				inputval2 = sys.argv[2].split("=")[1]
    
    				print(f"OutputValue:{inputval1} {inputval2}")
    
    				if __name__ == '__main__':
    				main()
    			

Related Links

See the following Laserfiche Github page to download blank script templates for your Python scripts.