Hi everyone,
I have found a few articles here on Answers that have helped me built this script. When I run this script as test directly on the script editor and use test tokens, it works perfectly. However, when I run this through workflow and get the metadata from the entries, I get the following error:
Here's my code:
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Data.SqlClient
Imports System.Text
Namespace WorkflowActivity.Scripting.Script
'''<summary>
'''Provides one or more methods that can be run when the workflow scripting activity is performed.
'''</summary>
Public Class Script1
Inherits ScriptClass90
'''<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 fileName as String
Dim numRows As Integer = GetTokenValue("RowCount")
Dim regDate as Date = Date.Now()
Dim strDate as String = regDate.ToString("ddMMMyyyy")
fileName = TokenReplace("Weekly Report - From "+"%(DateTokenCalculator_1WeekAgo#""MM-dd-yyyy""#) To "+"%(Date#""MM-dd-yyyy""#)")
My.Computer.FileSystem.CreateDirectory("D:\TestData\"+strDate+"\")
Dim csvWriter As New System.IO.StreamWriter("D:\TestData\"+strDate+"\"+fileName+".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 = "Employee Name,GL Account,Rate,Job Name,Job#,Reg Hrs Worked,Over Time Hrs Worked,Deduction Amount,Deduction Code(s)"
csvData.AppendLine(headerRow)
'Here is the first data row...
For Index As Integer = 1 To numRows
dataRow = TokenReplace("%(EmployeeName#["+Index.ToString+"]#)"+","+"%(GLAccount#["+Index.ToString+"]#)"+",,"+"%(JobName#["+Index.ToString+"]#)"+","+"%(JobNo#["+Index.ToString+"]#)"+","+"%(RegHrsWorked#["+Index.ToString+"]#)"+",,,")
csvData.AppendLine(dataRow)
Next Index
'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
End Class
End Namespace
Any help will be greatly appreciated!