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

Question

Question

Send email with created file (csv)

asked on November 22, 2016

I am using workflow to generate a csv file which is saved to a network folder.  I'm wanting to email this same file as part of the workflow, but I'm unable to attach the file via Email activity.  

I realize I can use Import Agent to retrieve the file from the network folder, but that seems like a lot of opportunities for failure, so I would like to avoid this.  

Also, I would like to save the file to a network folder AND to Laserfiche if possible.  Below is the code I'm using to generate the CSV file.  My vb.Net is not great, but it works for my needs.  If you have any suggestions on improving this script, please let me know.  

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Data.SqlClient
Imports System.Text
Imports Laserfiche.RepositoryAccess

Namespace WorkflowActivity.Scripting.SDKScript
    '''<summary>
    '''Provides one or more methods that can be run when the workflow scripting activity is performed.
    '''</summary>
    Public Class Script1
        Inherits RAScriptClass92
        '''<summary>
        '''This method is run when the activity is performed.
        '''</summary>
        Protected Overrides Sub Execute()
                'Wrap the code in a Try/Catch to catch any errors...
    Try
       'Instantiate a new streamwriter...
        Dim csvWriter As New System.IO.StreamWriter("\\prodlfqf\Attachments\Magna Orders\Magna Order " & me.GetTokenValue("Order Number").ToString & ".csv")
        Dim headerRow As String 'Will hold the header row values
        Dim orderRow() as string = me.GetTokenValue("PatternMatching_Order Number") 'Will hold the order data row
        Dim shipDate() as String = me.GetTokenValue("PatternMatching_Shipped on") 'Will hold the ship date
        Dim csvData As New StringBuilder    'We will append all of the data to this string object

        'Here is the order row...
        For n as Integer = 0 to orderRow.GetUpperBound(0)
        csvData.AppendLine("Order Number: " & orderRow(n))
        csvData.AppendLine("Shipped on: " & shipDate(n))
        Next n
        'Here is the header row...
        headerRow = "Line Number, Product Number ,Quantity Ordered, Quantity Shipped, Lot #"
        csvData.AppendLine(headerRow)

        dim myLineNumbers() as String = me.GetTokenValue("PatternMatching_Line Number")
        dim myProductNumbers() as String = me.GetTokenValue("PatternMatching_Product Number")
        dim myQuantityOrdered() as String = me.GetTokenValue("PatternMatching_Quantity Ordered")
        dim myQuantityShipped() as String = me.GetTokenValue("PatternMatching_Quantity Shipped")
        dim myLotNumbers() as String = me.GetTokenValue("PatternMatching_Lot #")

        For i as Integer = 0 To myLineNumbers.GetUpperBound(0)
            csvData.AppendLine(myLineNumbers(i) & "," & myProductNumbers(i) & "," & myQuantityOrdered(i) & "," & myQuantityShipped(i) & "," & myLotNumbers(i))
        Next i

        'Now write the CSV file and close the streamwriter...
        csvWriter.Write(csvData)
        csvWriter.Close

        'Cleanup...
        csvWriter = Nothing
        csvData = Nothing

    Catch ex As Exception
        'Send any error messages to workflow so they can be tracked...
        WorkflowApi.TrackError(ex.message)

    End Try
            'Write your code here. The BoundEntryInfo property will access the entry, RASession will get the Repository Access session
        End Sub
    End Class
End Namespace

Nate

0 0

Answer

SELECTED ANSWER
replied on November 22, 2016

Nate,

If you want to stick with native activities can you use the For Each File activity?  Configure it to look in the same folder as the csv and set the filter to only grab the correct CSV (maybe use a token to get the exact CSV filename)?  That activity exposes the correct object type to attach to an email.

0 0
replied on November 23, 2016

Thanks Cliff.  What's the best way to save the file to a Laserfiche folder?

Nate

0 0
replied on November 23, 2016

As Ian mentions on his post; I would use the Attach Electronic Document activity to attach the CSV to an existing (or new) LF document once you have a reference to the CSV in the For Each File activity...

2 0
replied on October 14, 2020

Thanks, this was the direction I needed to go in.

0 0

Replies

replied on November 23, 2016

Hi Nate,

 

We had the same idea as you and our solution was to - 

 

1. Create Entry in the specific folder you require. 

2. Attach Electronic Document to that created the entry. You can specify the windows folder and file name for which file to use

3. Email. In this activity, under attachments you can specify the created entry done previously. 

 

We've had no issues with it so far. 

 

Regards

Ian 

Email csv.PNG
Email csv.PNG (6.53 KB)
1 0
You are not allowed to follow up in this post.

Sign in to reply to this post.