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

Question

Question

SDK Script to Export CSV

asked on March 10, 2015

Good Afternoon,

I have the attached SDK Script code that is set to export a .csv file to C:\TestData.  The problem I'm running into is that the file is not passing tokens through to the CSV file.  I'm new to .NET but cannot figure out why the token value is not passing through to my CSV and I was hoping someone could help point me in the right direction.  Any help is much appreciated.  

Thanks,

Nate

        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("C:\TestData\Test.csv")
        Dim headerRow As String 'Will hold the header row values
        Dim dataRow As String   'Will hold the data row values
        Dim csvData As New StringBuilder    'We will append all of the data to this string object

        'Here is the header row...
        headerRow = "Column Name 1,Column Name 2,Column Name 3,Column Name 4"
        csvData.AppendLine(headerRow)

        'Here is the first data row...
        dataRow = "%(RetrieveFieldValues_Author), value 2, value 3" //This is where the token value is not passing through to my CSV
        csvData.AppendLine(dataRow)

        'Here is the second data row...
        dataRow = "Value 1, Value 2, Value 3, Value 4"
        csvData.AppendLine(dataRow)

        '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
End Sub

Capture.JPG
Capture.JPG (20.16 KB)
0 0

Answer

SELECTED ANSWER
replied on March 10, 2015 Show version history

Hi Nathan. You just need to tell the code to get the actual runtime value of the token for you. The code for this is fairly simple. He are 3 different ways of doing this kind of thing (assuming WF 9.2):

            Dim values1 As String 
            Dim values2 As String
            Dim entryIDValue As String
            
            values1 = me.TokenReplace("%(Entry ID) value1, value2")                        
            values2 = me.ReplaceTokensInString("%(Entry ID) value1, value2")
            entryIDValue = me.GetTokenValue("Entry ID")

For you, simply use me.TokenReplace on the string you are setting on the dataRow variable.

So:

 

dataRow = me.TokenReplace("%(RetrieveFieldValues_Author), value 2, value 3")

should do the trick.

1 0

Replies

replied on March 11, 2015

Flavio,

Thank you for your help, this worked great!  One other question similar to this...  If I'm using a token value (e.g. Pattern Matching Token) - Is it possible to get the PAGE NUMBER from that token?  If so, what's the code/logic to call the page number?

Thanks,

Nate

0 0
replied on March 11, 2015

Which page number do you mean exactly? Could you provide with an example of the usage you have in mind?

0 0
replied on November 18, 2016

Flavio,

I was finally able to get back to this and got it working to export my token value, so thanks a million for your help on that.  Next task is to get this to iterate through a multi-value token and export each new value as a new row.  I tried using a For Each loop, but was not successful.  Below is the code I'm using that exports the data for one row.  

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("C:\Users\lfadmin\Desktop\test.csv")
        Dim headerRow As String 'Will hold the header row values
        'Dim dataRow As String   'Will hold the data row value
        Dim csvData As New StringBuilder    'We will append all of the data to this string object

        'Here is the header row...
        headerRow = "Order Number, Shipped On, Line Number, Product Number ,Quantity Ordered, Quantity Shipped, Lot #"
        csvData.AppendLine(headerRow)

        'Here is the first data row...
        Dim  dataRow =  me.TokenReplace("%(PatternMatching_Order Number), %(PatternMatching_Shipped on), %(PatternMatching_Line Number),%(PatternMatching_Product Number), %(PatternMatching_Quantity Ordered), %(PatternMatching_Quantity Shipped), %(PatternMatching_Lot #)") 'This is where the token value is not passing through to my CSV
        For Each record As String in dataRow
            csvData.AppendLine(records)
        'csvData.AppendLine(dataRow)
        Next

        '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

 

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

Sign in to reply to this post.