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

Discussion

Discussion

Laserfiche SDK - Retreiving Multi FIeld Values - Function Not Implemented

SDK
posted on April 4, 2022 Show version history

We have been working with a developer who is following the SDK documentation and running into a confusion initializing a new FieldValueCollection.

They copied the code from the documentation for RepositoryAccess

Here is their code

 

 

However when debugging they get told the following line is invalid FieldValueCollection FVC = EI.GetFieldValues();

It says that FVC.SyncRoot threw an exception of type System.NotImplementedException

I don't even see where in the documentation we are calling anything called SyncRoot, this must be done in the initializers of the FieldValueCollection class. How are we calling a non-implemented function?

0 0
replied on April 5, 2022 Show version history

Here is a VB function (easily converted to C#) that takes an EntryID and field name and returns a List<Object> with any value(s).  It works on both regular and MultiValue fields.

    Private Function GetValueFieldValues(ByVal iEntryID As Integer, ByVal sFieldName As String) As List(Of Object)
        Dim lstReturn As List(Of Object) = New List(Of Object)
        Try
            Using ent As EntryInfo = Entry.GetEntryInfo(iEntryID, RASession)
                Dim AllFields As FieldValueCollection = ent.GetFieldValues()
                Dim FieldValue As Object = AllFields(sFieldName)
                If TypeName(FieldValue) = "Object()" Then
                    lstReturn.AddRange(FieldValue)
                Else
                    lstReturn.Add(FieldValue)
                End If
            End Using
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
        Return lstReturn
    End Function

Note:  Change the RASession variable name to whatever you Session object is named.

1 0
replied on April 4, 2022

Is this the exact code that is failing? Nothing here is referencing the SyncRoot property of the object, which implies that it is referenced internally. So in order to help you, we would need an accurate stack trace.

All that said, don't use the SyncRoot property. If you really need to synchronize access to the object, allocate a dedicated object to lock on.

0 0
replied on April 5, 2022

I belive that is what the developer is asking, why is the error mentioning a method called SyncRoot when there is no no call to it.

It says specifically FVC.SyncRoot which implies that the initialization function of the FieldValueCollection class must have an internal call to SyncRoot.

The only information I could get from screenshots of their dev enivornment is that SyncRoot is a method of ICollection, and ICollection is a member of the FieldValueCollection class. It says FieldValueCollection : ICollection when you look at the cs file.

As a VAR the one thing we don't get access to is any of the documentation or the SDK libraries, but a developer might reach out to their VAR to get help if they get stuck so this is the situation happening here. I don't know if the SDK includes a support package from another organization. I think this is the first time we have run into a company that purchased the development kit.

If these workarounds do not work for them, I am trying to get an isolated command line project that demonstrates the issue for a support case.

0 0
replied on April 7, 2022

Yes, that's the question, but it's not really answerable without code to reproduce their issue. The challenge is the code shown does not seem to have a line that would produce that error, and yet the reported message strongly implies that the call is in their code and isn't internal to the SDK. (This is based on the variable name "FVC" being included in the message - that is what the object is named in their code, and would not be included in an error originating internally.) This is why code to reproduce the issue is essential for SDK problems - otherwise we have to read between the lines and guess. It also removes the opportunity for miscommunication about the error.

Maybe the developer can post an update here directly? It would seem faster and easier for everyone.

0 0
replied on April 7, 2022

It is the following that is failing, which they copied right out of the documentation. If the workaround's don't work I can talk to the dev about creating a support account and show him the answers site.

0 0
replied on April 4, 2022

I might get my hat handed to me from the likes of @████████, but I think there's too many assumptions going on here.  We assume that FVC["Service Type"} is actually populated, and we assume that FVC["Service Type"] is populated twice (an array).  If it's only populated once, then it's just a string.

This code will ensure an array(yeah, ok, it's a list) of string

 

 public static List<string> GetMultiValuedFieldValues(object[] obj)
        {
            List<string> result = new List<string>();
            
           
            if (obj == null) return result;
            if (obj is string)
            {
                result.Add(obj.ToString());
            }
            else if (obj is object[])
            {
                foreach (object objArrayValue in (object[])obj)
                {
                    result.Add(objArrayValue.ToString());
                }
                return result;
            }
            return result;
        }

 

2 0
replied on April 4, 2022

Awesome, I would make an assumption that all multi-value fields are an array as they could have more than one value, but I bet most documents do not have more than one value.

Will try this out, when I can get back with the programmer who has the SDK.

0 0
replied on April 5, 2022

A multivalue field with a single value does not return an array when you try to retrieve the value(s).

1 0
replied on April 8, 2022

The programmer responded back that this extra function solved their problem! Thank you. I am informing him of how to setup an Answers account.

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

Sign in to reply to this post.