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 script file on the remote agent host. Supported file extensions are .dll for C# scripts, .py for Python scripts, and .js for Node.js scripts. By default, place the script in C:\Program Files\Laserfiche\ProcessAutomationWorkerAgent\LFPALocalAgent\bin. For example, the full path to a C# script might be C:\Program Files\Laserfiche\ProcessAutomationWorkerAgent\LFPALocalAgent\bin\Script.dll. If the remote agent worker was installed in a different location, use the bin subfolder of the worker folder (for example, LFPALocalAgent) in that installation folder. See Default worker installation folders. 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.
  5. Optional: Modify C:\Program Files\Laserfiche\ProcessAutomationWorkerAgent\LFPALocalAgent\bin\plugin_settings.json to allow the worker to access scripts stored outside the default bin folder. If the remote agent worker was installed in a different location, modify plugin_settings.json in the bin subfolder of the worker folder in that installation folder. Append the additional paths to the AllowList attribute in the RemoteScriptSourcePlugin block. For example, to allow access to the entire C:\ drive and a shared network path, update the attribute to "AllowList": [ "C:\\", "\\\\samplehost\\scriptsfolder" ]. If you have multiple remote agent workers, store all scripts in a single folder that all workers can access. The remote agent worker must be able to access each specified path. For example, if a script is stored in a folder that only your own Windows account can access, the remote agent worker cannot read the script. After modifying the local configuration, restart the remote agent service for the changes to take effect.
  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 script file with the .js extension 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 script file with the .py extension 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.