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

Question

Question

Problem with sdk script retrieving field names and values

asked on December 11, 2017 Show version history

I have an SDK  based application that will export data and electronic doc to a defined folder and am trying to convert this to be used in the workflow engine as a SDK script. The bits that export the document are working fine, but I am having issues getting the CSV to work.

The expectation is that I will be generating a CSV with two lines. One with Field Names and the second with the corresponding values.

When I view the CSV created by the script, it only contains the values that I added at the bottom (originalname and path)

 

I believe the issue is I am getting zero results in my FieldValueCollection, so it nevers enters the loop to create line1 and line2.

 

Any pointers on what I am doing wrong here?

 

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

Namespace WorkflowActivity.Scripting.SDKScript
    Public Class Script1
        Inherits RAScriptClass102
        Protected Overrides Sub Execute()
            'Write your code here. The BoundEntryInfo property will access the entry, RASession will get the Repository Access session
        Dim exportroot As String ="C:\LFExport\"
        Dim csvroot As String = "C:\LFExport\CSV\"
        Dim entryid As Integer = CInt(TokenReplace("%(doctoexport)"))


        Try
                Dim docInfo As DocumentInfo = Document.GetDocumentInfo(entryid, RASession)
                Dim fvs As FieldValueCollection = docInfo.GetFieldValues()
                'Dim fvs as FieldValueCollection = BoundEntryInfo.GetFieldValues()

                Dim line1 As String = String.Empty
                Dim line2 As String = String.Empty

                'create csv lines
                For i As Integer = 0 To fvs.Count - 1
                    Dim fieldName As String = fvs.PositionToName(i)
                    Dim fieldVal As Object = fvs(i)
                    Dim f As FieldInfo = Field.GetInfo(fieldName, RASession)
                    Dim formattedVal = f.ValueToString(fieldVal).Replace(",", "-")
                    line1 = line1 & fvs.PositionToName(i).Replace(",", "-") & ","
                    line2 = line2 & formattedVal & ","
                Next

                line1 = line1 & "originalname,path"
                line2 = line2 & docInfo.GetLocalName() & "," &  fullPath

0 0

Answer

SELECTED ANSWER
replied on December 12, 2017 Show version history

Hi Steve,

Not sure exactly what is going wrong with your process, but the following seemed to work for getting the field's name/value. I usually add MsgBox calls in various places so I can run the script in the editor and test each step to see where it is getting caught up.

            'Dim doc As DocumentInfo = Document.GetDocumentInfo(Me.BoundEntryId,RASession)
            Dim doc As DocumentInfo = Me.BoundEntryInfo
            Dim fvs As FieldValueCollection = doc.GetFieldValues()
            
            For i As Integer = 0 to fvs.Count - 1
                Dim fieldName As String = fvs.PositionToName(i)
                Dim fieldVal As String = doc.GetFieldValue(fieldName)
                MsgBox(fieldName + " | " + fieldVal)
            Next

If that is all you're doing with the documentInfo object, you can probably skip that part entirely and just call the field values directly from the BoundEntryInfo object like so

            Dim fvs As FieldValueCollection = Me.BoundEntryInfo.GetFieldValues()
            
            For i As Integer = 0 to fvs.Count - 1
                Dim fieldName As String = fvs.PositionToName(i)
                Dim fieldVal As String = Me.BoundEntryInfo.GetFieldValue(fieldName)
                MsgBox(fieldName + " | " + fieldVal)
            Next

 

1 0
replied on December 12, 2017

Thanks Jason!

 

The problem actually turned out to be user error (mine). The document I was using did not have any fields assigned so the code was working as it should. DOH!

0 0
replied on December 12, 2017

We've all been there! Glad to hear you got it working yes

0 0

Replies

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

Sign in to reply to this post.