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.