posted on March 17

I've seen some examples on how to run executables using Workflow, but hadn't seen a lot of documentation on how to return a value from the executable back to Workflow (and therefore back to Forms).

In my particular use case, I had to supply the executable with parameters from the initial form, so I started by retrieving the process variables from the Forms process. I then used "Assign token value" to reformat those parameter variables as needed, then ran the C# script below to generate the output value and assign it to a response variable. The executable in this example required parameters of ResponseCodeStr, Time, and SharedKey, so obviously you'd have to replace those with whatever you need to pass to your own executable. The fancy part is starting a System Diagnostics process and capturing the output to stdout, then formatting and returning that output.

namespace WorkflowActivity.Scripting.GenerateResponseC
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Text;

    /// <summary>
    /// Provides one or more methods that can be run when the workflow scripting activity is performed.
    /// </summary>
    public class Script1 : ScriptClass90
        /// <summary>
        /// This method is run when the activity is performed.
        /// </summary>
        protected override void Execute()
            // Write your code here.
            // Create and initialize ProcessInfo structure
            System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
            System.Diagnostics.ProcessStartInfo myProcessInfo = new System.Diagnostics.ProcessStartInfo();
            string ResponseCodeStr = TokenReplace("%(ResponseCode)");
            string Time = TokenReplace("%(RetrieveBusinessProcessVariables_Code_Type)");
            string SharedKey = "XXXXXXX";
            myProcessInfo.FileName = "\\Path\\to\\file.exe";
            myProcessInfo.Arguments = ResponseCodeStr + " " + Time + " " + SharedKey;
            myProcessInfo.RedirectStandardOutput = true;
            myProcessInfo.UseShellExecute = false;

            // Start a new process
            var process = System.Diagnostics.Process.Start ( myProcessInfo ) ;
            var output = process.StandardOutput.ReadToEnd();
            string OutputFormatted = output.ToString().Trim();
            OutputFormatted = OutputFormatted.Replace("Generated Response: ","");

After the "ReturnCode" variable is set to equal the formatted output value, it's easy to set the value of the business process variable in your Laserfiche Forms process. Hope this helps!

1 0