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

Question

Question

Reading files from Forms in Workflow

asked on May 31, 2017

I have a process where a user uploads a file or files in a form, and a workflow is started after they submit. In the workflow, I want to read the contents of the file(s) into a token and then use that token in a SQL query (literally pass the contents of a file to SQL for each file). I've tried using a script, or saving the file temporarily to the file repository and using the "Retrieve Document Text" action in Workflow, but the token is always empty. I've tried the "Retrieve Document Text" token as the root token, or with an index of 1. Any thoughts on what I'm doing wrong? Or is there any easier way to do this? I would think this is a simple action for Laserfiche.

0 0

Answer

SELECTED ANSWER
replied on June 1, 2017 Show version history

Solution:

For anyone looking for how to do this, a workflow (as shown in the image) where the attach electronic document attaches to the "Create Entry > OutputEntry", and the SDK Script also has a default entry of "Create Entry > OutputEntry" will allow the files to be easily accessed in the script.

string contentType;
//the "using" keyword provides automatic cleanup of the object once code has completed
using(LaserficheReadStream file = Laserfiche.RepositoryAccess.Document.ReadEdoc(BoundEntryId,out contentType,RASession)){
    //create a byte array that is the correct size of the file
    byte[] result = new byte[file.Length];
    //read the file into the byte array
    file.Read(result,0,result.Length);
    //save the result, encoded back into a string,
    this.SetTokenValue("SDKScript_FileData",System.Text.Encoding.Default.GetString(result));
}

The Create Entry item can be deleted after the code. This leads to having a token with the file's contents, which I was then passing to a SQL script for some dynamic manipulation.

1 0

Replies

replied on May 31, 2017

Retrieve Document Text only reads text pages from documents already in Laserfiche. I'm guessing your document is saves as an electronic document. So you'd have to script downloading it and generating a token from its contents.

0 0
replied on June 1, 2017

What do you mean by script downloading it? The process I've tried (that doesn't work) is attached.

If you mean using a C# script, are there any examples anywhere? I've looked through here and Laserfiche's online documentation, and details on how to use the Laserfiche references in code are sparse...

Workflow.png
Workflow.png (9.33 KB)
0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.