I was attempting to pull data from multi-value fields specifically from the Laserfiche Cloud environment through the SDK. I wanted to know if this was intended behavior for the SDK. When pulling data from a multi-valued field into an dynamic object array it works and I'm able to iterate through the object array. The issue is this only works when there is more than 1 value for the multi-valued field. If there is only a single value nothing is retrieved. I have to put a try/catch to see the count of items in the object array. If it sees it as an empty array I grab the field data and pass it to a string or another data type depending on the field type. Am I missing something or is this intended behavior?
Question
Question
Obtaining values for multi-value field in SDK
Answer
What do you mean when you say "nothing is retrieved"? When there is a single value, the FieldValueCollection class should return a .net object (not an array) with the value. You can use the following sample code to make an array from the field values no matter how many values there are:
object fieldVal = fvc[fieldName]; // The raw value, could be a single value or an array // Make an array and populate it with the field values var values = new List<object>(); if (fieldVal != null) { var valArray = fieldVal as Array; if (valArray != null) { foreach (object val in valArray) { values.Add(val); } } else values.Add(fieldVal); }
I'll utilize the snippet that you provided. I was using the RA[C#] sample from the SDK documentation. The snippet
// Retrieves a document EntryInfo EI = Entry.GetEntryInfo("\\Doc", mySess); // Retrieves all the field values assigned to the document. FieldValueCollection FVC = EI.GetFieldValues(); // We're only interested in the values for a multiple-value field // named "FieldName" object[] multivalues = FVC["FieldName"] as object[]; for (int i = 0; i < multivalues.Length; i++) Console.WriteLine(multivalues[i]);
When iterating through the loop that was provided in the sample I receive a null pointer exception when there is only a single value in a multi-value field. In the case that there are 2 or more items listed then the sample I provided from the documentation works with no issues.
The sample code looks out of date, we will look into fixing that.
Hello Robert,
Can you help me for this post.
We don't want to skip value in multi-value as we need to show them in excel with correct order of remaining multivalue field.
Thanks,
pratik