You are viewing limited content. For full access, please sign in.

Question

Question

Generate CSV

asked on March 18, 2021

I saw a previous post that indicated we could use SDK activities in Cloud.  I only see the Run Script option in cloud, are they the same thing?

We need workflow to query a database and generate a csv file to local drive.  We do this all the time in on prem workflow.  Now we need to do it in Cloud.

From what I gather, we need to install a Worker on the users workstation, then create a script that generates the csv based on the return from the SQL query to the local drive where the worker is installed.

Is this roughly accurate?  Any examples or items to start with?  Basically needing to query an Invoice table and for each row write the gl info.

 

Thanks,

Chris

0 0

Answer

SELECTED ANSWER
replied on March 19, 2021 Show version history

Hi Chris,

From what I can see the Run Script Rule has replaced the Script/SDK Script function. This means that the script would need to be set up in advance and then called by Workflow.

 

Here is a quick example of the steps I'd take:

 

  1. Go to Integrations and set up the Remote Agent - it should have a Queue with the Remote Script Source Plugin and a Worker installed on the server that will be running the script.
  2. Go to Rules and create a Script called GenerateCSV - it should be assigned to the Remote Agent you just set up. Your script itself can be written in C#, Python or NodeJS (in the below example I use C#).
  3. Open Visual Studio and create a Class Library (.NET Framework) project.
  4. Use the following code:
    public class MyClass
        {
            public static Task<IDictionary<string, object>> MyScript(IDictionary<string, object> inputsFromRule)
            {
                //Initialize a Dictionary to store your outputs
                var output = new Dictionary<string, object>();
    
                // Build an SQL query based on the Input parameters - this is just a quick example
                string SQLquery = "SELECT * FROM "+ inputsFromRule["tableName"]+" WHERE "+ inputsFromRule["firstParameter"]+" = "+ inputsFromRule["secondParameter"];
               
                // TODO: Run SQL query, build and save your CSV file
    
                // Determines what output to send back - change this bool based on if the file was saved or not
                bool successfullyCreatedFile = true;
    
                // Change the output status
                if (successfullyCreatedFile)
                {
                    output.Add("status", "Successful");
                }
                else
                {
                    output.Add("status", "Failed");
                }
    
                // Return this status
                return Task.FromResult<IDictionary<string, object>>(output);
    
            }
        }

     

  5. Build a Release version of the project and save the DLL file to the following location on the machine where the Worker is installed (you may need to change the LFPALocalAgent folder to LFPALocalAgent2 or LFPALocalAgent3 based on what Worker is being used): C:\Program Files\Laserfiche\ProcessAutomationWorkerAgent\LFPALocalAgent\GenerateCSV\bin
  6. Return to the Script you made in Laserfiche Cloud and use the following settings:
  7. When you test it, it should return "Successful" as I did not change the bool value.
  8. Now in Workflow you can configure the following:

 

This example is a quick overview and should hopefully be a good starting point for what you want to accomplish.

6 0
replied on March 19, 2021

Thanks much for taking the time to post.  I kind of had the general outline steps but this is much more clear.  Will give this a try and starting testing to get it up and working.  Much appreciated!

1 0
replied on June 23, 2022 Show version history

When I try all the steps you gave I get the following error when I click "Test Script":

Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

Any guidance here would be much appreciated!

 

More info:

I was able to get the NETFramework version of this https://support.laserfiche.com/download/4146 working, but I am still getting the above error for NET Core 3.1 and NET6. I installed the runtimes and still no luck, then I installed the worker on my local dev machine and still no change. I also tried the script created following these instructions: https://doc.laserfiche.com/laserfiche.documentation/en-us/Subsystems/ProcessAutomation/Content/Resources/Rules/scripts.htm

0 0
replied on July 19, 2022

I'm also receiving this error message using the template script (with modifications for variable names and values) provided by LF - was there ever a solution to this?

0 0
replied on July 19, 2022

Using NET Framework solved the issue for me. I never got it working on the later frameworks. Sorry.

2 0
replied on July 19, 2022

Thanks!

1 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.