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

Question

Question

Forms fields to create a CSV file with workflow

asked on April 28, 2023

I would like to create a CSV file with workflow and have that emailed to a client.  Does anyone have experience with this?

1 0

Replies

replied on April 28, 2023 Show version history

As with anything in Workflow, there are probably multiple ways to do this.

Here's how I do it.

This example creates an entry in the Repository with the text of the entry formatted as CSV, then it emails a copy of that text to a user.  It comes across as a .txt file, but it is formatted as a CSV, and that has worked well enough for our needs.

Let's say we are doing a database query to create the file, and the query returns three columns of data: record_number, status, date

  1. "Query Data" activity to rerieve the three variables from the database.
  2. "Assign Token Values" activity.  Create a multi-value token named "Report Lines", populate one line with Record,Status,Date.
  3. "For Each Row" activity to loop through the results of the "Query Data" activity.
    1. "Assign Token Values" activity - append to the "Report Lines" token the following:   
      %(ForEachRow_record_number),%(ForEachRow_status),%(ForEachRow_date)
  4. "Assign Token Values" activity.  Create a single-value token named "Report Text".  Populate it with the "Report Lines" token, set to Apply Index with All Values Separated by Line Break.
  5. "Create Entry" activity.  Create a document.  Select the name and path as applicable for your environment.
  6. "SDK Script" activity.  Set it to use the Output Entry from the "Create Entry" activity.  Give it the script posted below.  This takes the text of the "Report Text" token and adds it to the entry.
  7. "Retrieve Document Text" activity.  Set it to use the Output Entry from the "Create Entry" activity.  This isn't needed for the email - my live process used this for something else, but the email doesn't use it, so you can exclude this step.
  8. "Email Report" activity.  As an attachment, include the Output Entry from the "Create Entry" activity.  Set it's properties to "Attach a copy of the document" and "Include page text (separate text file)", and uncheck everything else.  Since the entry is just the text, there wouldn't be anything besides the text anyway.

 

Looks something like this:

     

 

And here's the script - this is C#:  

        protected override void Execute()
        {
            using (DocumentInfo doc = Document.GetDocumentInfo((int)GetTokenValue("CreateResultsEntryReport_OutputEntry_ID"), this.RASession))
            {
	            doc.AppendPage();
	            PageInfo PI = doc.GetPageInfo(1);
	            PI.WriteTextPagePart(GetTokenValue("Report Text").ToString()); //You can use GetTokenValue...ToString() here to insert your text from tokens
	            PI.Save();
            }
        }

 

6 0
replied on May 31, 2023

Thank you for the response, Matt!

 

If I am not pulling data from a database and just from a Laserfiche forms submission; could I use “Retrieve Business Process Variables” instead of using the “Assign Token Values” for the information that I need? I have done this to populate a pdf and email it in the past.

In the C+ script (using Laserfiche.RepositoryAccess;), is it accessing a template file in the Repository then populating that file with the information?

I am not a programmer, so I do not understand C+ scripting very well. Trying to understand it the best I can.

0 0
replied on May 31, 2023

You could swap out the “Retrieve Business Process Variables” activity instead of the “Query Data” activity.

The script is just adding the text in to the entry in the repository.

0 0
replied on February 23, 2024 Show version history

This is very helpful, thank you. I am also not well versed in C# so I wanted to ask if there is a way to display the token values in table format. I am sure the tokens will have to be assigned separately then?

0 0
replied on February 23, 2024

The C# isn't doing anything with the formatting of the text, all it is doing is taking the token and applying it to the text element of the entry in the repository.  Additionally, the text element of the repository doesn't include any formatting, it's like a basic text document.

Instead of the commas that were used in steps 2 and 3 of my instructions, if you wanted to do some creative spacing to make the text appear sort of "table-like", going for something like this: 

Col A        Col B        Col C
John         Jane         Joe
123.45       12.34        1.23
01/01/2001   02/02/2002   03/03/2003

Then you should actually be able to do that via the various token editing activities within Workflow, before the script even runs.

0 0
replied on February 23, 2024

I am doing something very similar to Daniel where I am using a Laserfiche form. I am using your method to get the values input into a specific table and displaying them on a txt file that is emailed out, I did manage to sort out the formatting by using the Bar dropdown option. The new issue I am facing is that if there is a 2nd row added to the table it will display the table data as follows:

Sales Order | Sales Order | INVXXXXX | INVYYYYY | 867.00 | 548.00 | 121.38 | 76.72 | 988.38 | 624.72 

Any advice on how I can edit my workflow to display the new table row on a new row in the txt file?

replied on February 26, 2024

Okay thank you for the information. I will give the token editor a shot.

0 0
replied on February 27, 2024

Hi Matthew

I need some help, right now this is the format I am getting on my text element when there is a single table row:

INV00001 | Invoice | 1000.00 | 0.00 | 1000.00 

This is my format when I add a 2nd row:

INV00001 | INV00002 | Invoice | Sales Order | 1000.00 | 1250.00 | 0.00 | 0.00 | 1000.00 | 1250.00 

I understand why it is displaying it in that format but have no clue how to separate the two table rows using the token editor.

 

This leads onto my 2nd question. Is there a way to edit the C# so that it will push multiple single token values to the text element (One token value for each table column). If this is possible, I will be on the right track as then I feel I will be able to use the token editor to display each row on a new line.

replied on April 2

I attempted to follow the directions and I got this. Does anyone know why the Select Collection is blank? 

0 0
replied on April 2

Make sure you selected the table(s)/collection(s) on your Retrieve Business Process Variables activity.

If that still doesn't work, I would recommend as a new question so that it is seen by more people who may be able to respond more quickly (posting to older items like this only alerts those of us who originally contributed to the item).

0 0
replied on April 2

I am retrieving from a form.

I need to collect the data from a form submission and email that csv file to the network administrator. 

0 0
replied on April 3

Yes, I understand that, and the "Retrieve Business Process Variables" activity is the correct activity to get that data from the form submission.

But you asked why the "For Each Row" activity was not listing any options.  That activity is expecting several different types of objects, which can include tables and collections from the form.  As long as you have selected the variables for those table(s)/collection(s) as part of the "Retrieve Business Process Variables" activity they will show up as being selectable as part of the "For Each Row" activity.

0 0
replied on April 3

Thanks for responding. Can you give me more information as I do not see that option anywhere. I am using Workflow 11 desktop.

0 0
replied on April 3

On your "Retrieve Business Process Variables" activity - after you have selected the server and the process - click where it says "Click here to select which fields to retrieve".

It will give you a list of all of the variables on the Forms process.  You can search by name, and you should see all of the variables within your table(s)/collection(s) and the variables for the table(s)/collection(s) themselves.  You specifically are wanting to select the variables for the table(s)/collection(s) themselves.  You will be able to tell you are looking at the right thing, because the "Type" column will list the type as Table* or Collection*.

After you have done that, you'll be able to select the table/collection on the "For Each Row" activity.

0 0
replied on April 3

Okay, that helped a lot. I am new to this and this is not under the help documentation. 

 I do have objects under fields they are coming from just a form. 

It sounds like since I do not have a table that I do not need the For Each Row. But I am not, I am just pulling from a field.  I did remove the For Each Row already. 

I think I either need to chat with you in an email or I need to submit a ticket and ask where I am going wrong. I

 

0 0
replied on April 3

Yeah, you wouldn't need the "For Each Row" activity if you are not working through a Collection or Table.

Do you even need it as a CSV file if it is just a couple fields?  You can just include the tokens from the form into the body of the email and simplify the workflow drastically.

0 0
replied on April 4 Show version history

Oh no, this is just the test workflow. Once I get this working I will setup the one I actually need. 

We have an onboarding process in forms and the Network Admin to automate account creation. So it must be a csv file.

I took the For Each Row out and I have all green (actives go), The code has no errors, the CSV gets created, but no token data gets written to it. I am so close! I am missing something. How to get that data into the CSV file. 

I narrowed this down to the file path. 

0 0
replied on April 4

From what you are saying, the most likely issue is related to the tokens referenced by the script.

  1. Make sure the "SDK Script" activity has actually selected that the entry it is targeting is the entry created by the "Create Entry" activity - this is selected at the bottom of the activity properties (below the actual script).
  2. Double check the token names from the "Assign Token Values" activity and the "Create Entry" activity match how they are named within the SDK Script.
    • I noticed the script I originally posted back in 2023 might have a typo with the "Create Entry" activity's token not matching what is in the script.
      • Line 2 of the script I posted includes this: GetTokenValue("CreateResultsEntryReport_OutputEntry_ID")
      • But based on the screenshot showing the activity just named "Create Entry" - that reference to the token should likely be: 
        GetTokenValue("CreateEntry_OutputEntry_ID")
    • Line 7 of the script includes this:
      GetTokenValue("Report Text")
    • Make sure the token you created in the "Assign Token Values" activity is exactly listed here - if you named it something different than "Report Text", that different name should be listed in the script.
0 0
replied on April 4

I moved away from that script a bit. 

I ran a test creating the file to my Desktop. It worked. It created and wrote the token values to it. So it has to be the path. 

I was using the same path as the Create CSV file. I then tried the path from the Entries tab.  Now I am stumped. I will see if Support can Help me. 

0 0
replied on April 4

Okay, it will be a week before they can help me. 

I have gone back to your script. 

1. I am not using the for each row as I am not using a table but a form

2. I used the Token Browser for the both Token Values

3. SDK activity, Script's Default Entry:  "Other Entry" has two options OutputEntry and Destination (I guessed OutputEntry)

I tried to test it but it's asking me for the value to GetTokenValue("CreateFILE_OutputEntry_Name")

I run it from the Test From and the new file in the repository is empty. 

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

Sign in to reply to this post.