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

Question

Question

Get and set a multi value field in VB .NET

asked on April 28, 2014

 How do I get and set multi value fields in a VB script in workflow? Ideally I want to use a string array.

 

Thanks for the help!

0 0

Replies

replied on April 28, 2014 Show version history

Multi-value fields in RA have values of type IEnumerable. If you have a text field, you should simply be able to use an array of Strings to set the field value.

 

Retrieving the values already in the field is slightly more complicated. The main thing to remember is that GetFieldValue will return an IEnumerable, not an IEnumerable<string>. If you wanted to make a String array out of the returned IEnumerable, you would use something like this:

' Your EntryInfo (which can be a DocumentInfo or a FolderInfo)
Dim entry as EntryInfo
'You field's name
Dim field as String

' Get the IEnumerable field value
Dim values As IEnumerable = entry.GetFieldValue(field)
' Create a list to hold the values
Dim valuesAsArray As New List(Of String)
' Iterate through, converting to String
For Each value As Object In values
    valuesAsArray.Add(value.ToString())
Next

This sample is untested and won't cover all cases, so be sure to test it if you use it. The general idea, however, should apply to your case. Get the IEnumerable, convert its elements to the particular type, and store them in a Collection. If you can't use the List(Of String) produced here in other parts of your code, you can convert the List to a String array with the ToArray method.

0 0
replied on April 29, 2014 Show version history

Thanks for the help, but I have a few questions.

 

Where does the doc come from in line 7? Am I supposed to declare that somewhere or is that a global variable?

 

As far as setting a field do is it something like

doc.SetFieldValue("field name",myArray)

 

0 0
replied on April 29, 2014

The doc on line 7 was supposed to be 'entry'. I've edited the original reply to fix that.

 

To set the field value there are a couple steps:

 

  1. Get a FieldValueCollection object. If you want to completely overwrite the metadata on your entry, you can do that with the FieldValueCollection constructor. If you want to change the existing metadata, you can use the GetFieldValues method on your EntryInfo.
  2. Update the FieldValueCollection. You can add IEnumerables directly to the collection using the Add method.
  3. Use SetFieldValues on your EntryInfo with your edited FieldValueCollection to set the field values.
  4. Call Save on the Entry.
  5. Dispose of your EntryInfo appropriately.
0 0
replied on September 23, 2014 Show version history

Here's some sample code we put together for a test application.  The object model is nice, but we find we have to whack away at things until we get the sequence of events, and the relationship between the different objects in alignment. In the example below, we both retrieve and set the contents of a list field.  Note that you pretty much have to replace the whole thing at once, as it does not act at all like a collection.

To update a list, you manipulate the FieldInfo object, and then call the FieldUpdate event, which is where the values are posted to the field. Reading the values is the reverse.

 

            Dim LF_FieldInfo As Laserfiche.RepositoryAccess.FieldInfo
            Dim LF_FieldID As Integer = 0
            Dim LF_ItemList As Laserfiche.RepositoryAccess.FieldItemList
            Dim LF_ListValue As String = vbNullString

            'In this next line, "List" is actually the name of the field and not a parameter.

            'See notes below for how to get this Session object...also tricky business.

            LF_FieldInfo = Laserfiche.RepositoryAccess.Field.GetInfo("List", LF_Session)
            LF_FieldID = LF_FieldInfo.Id

            'Testing: Set the new values
            Dim sActiveClients As String()
            Dim sTemp As String = vbNullString
            sTemp = "A/B/C/D/E"

            'We toggled back and forth to make sure something was happening
            'sTemp = "T/U/V/W/X"
            sActiveClients = Split(sTemp, "/")

            'Push the array to the FieldInfo Object
            LF_FieldInfo.SetItemList(sActiveClients)

            'And call the update
            Laserfiche.RepositoryAccess.Field.Update(LF_FieldID, LF_FieldInfo, LF_Session)

          

           'Here we are appending values to the existing list.
            Dim sInactiveClients As String()

            sTemp = "1/2/3/4/5"
            sInactiveClients = Split(sTemp, "/")

            'Refresh the list in memory
            LF_ItemList = LF_FieldInfo.GetItemList()

            Dim nIndex As Integer = 0
            For nIndex = 0 To UBound(sInactiveClients)
                LF_ItemList.Add(sInactiveClients(nIndex))
            Next

            'Update the Field
            Laserfiche.RepositoryAccess.Field.Update(LF_FieldID, LF_FieldInfo, LF_Session)

            'Refresh the list in memory
            LF_ItemList = LF_FieldInfo.GetItemList()

            'And Check/Retrieve the results
            For Each LF_ListValue In LF_ItemList
                MsgBox(LF_ListValue)
            Next

 

We create the session object elsewhere, using this:

            ' Log into the repository
            Dim repository As New RepositoryRegistration(sServerName, sRepoName)
            Dim LF_Session As New Session()
            LF_Session.LogIn(sUserName, sPassword, repository)

 

There are some further tricks to make this work as a workflow sdk script task, and I have posted that elsewhere.  Search for "Change RM properties in Workflow SDK".

 

All code guaranteed to work 100%, or your money back!

0 0
replied on January 4, 2017 Show version history

Can anyone provide the c# code to add a new value to an existing List using the sdk.

 

 

Thanks

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

Sign in to reply to this post.