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

Question

Question

LF SDK problem with getting group stage with multivalue fields ( if multivalue field is blank)

asked on April 9, 2023

Hello Team,

I need help in SDK script for fetching template field.

As per template , we have one group "Rulemaking Stage" having multiple value inside it. I want to access/get those values in sdk.

ex. As per screenshot we have 2 different fields "Rulemaking Stage" and "Date received" inside the "Rulemaking Stage" group with below data entered.

Notice - 1/2/2023
Advance Notice of Proposed Rulemaking - 2/3/3023
Final Rule -
Other -
Interim Final Rule - 3/3/2013

As per above we have 5 different values but out of this 2 values blank in date fields but when I am fetching it from SDK its returning 3 values which are not blank hence my one-one relationship was not maintaned.

Actually I want to create excel report and need to show rows as per entered value but somehow blank value going to be skipped while fetching,

Please find the screenshot for more details.

As per screenshot in programming rulemaking stage having 5 values but date received returned only 3 values and skipping blank values. ( see RulemakingTotalFive.png and DateReceivedTotal3.png)

See how we have set blank value in date received field in screenshot ( BlankDatereceived.png)

Thanks,
Pratik

BlankDatereceived.png
DateReceivedTotal3.png
RulemakingTotalFive.png
TemplateScreen.png
Excelscreen.png
Excelscreen.png (10.02 KB)
0 0

Answer

SELECTED ANSWER
replied on April 18, 2023

sample code attached if having some issue to read it

0 0

Replies

replied on April 14, 2023

Multi-value field groups require some extra processing. The FieldValueCollection will return an array of values and omit blank rows. The GetFieldRowNumbers method returns a list of row numbers that maps from the value array to the row each value belongs to. Here is sample code that will generate a list with the values for each row:

EntryInfo entry = Entry.GetEntryInfo(entryId, session);
FieldValueCollection fvc = entry.GetFieldValues();

List<int> multivalueFieldGroupIds = new List<int>();

// Find all multivalue field groups for this entry (usually only one is defined on a template)
foreach (var fieldName in fvc.FieldNames)
{
    int groupId = fvc.GetFieldGroupId(fieldName);
    if (groupId > 0 && !multivalueFieldGroupIds.Contains(groupId))
        multivalueFieldGroupIds.Add(groupId);
}

// Loop over the multivalue field groups (usually only one is defined on a template)
foreach (var groupId in multivalueFieldGroupIds)
{
    List<string> fieldGroupFields = new List<string>();

    // Find the fields in this multivalue field group
    foreach (var fieldName in fvc.FieldNames)
    {
        if (fvc.GetFieldGroupId(fieldName) != groupId)
            continue; // Belongs to a different field group

        fieldGroupFields.Add(fieldName);
    }

    int highestRow = 0;

    // Calculate how many rows are in the multivalue field group for this entry
    foreach (var fieldName in fieldGroupFields)
    {
        var rowNumbers = fvc.GetFieldRowNumbers(fieldName);

        if (rowNumbers == null)
            continue;

        foreach (var rowNumber in rowNumbers)
            highestRow = Math.Max(highestRow, rowNumber);
    }

    var valuesForAllRows = new List<Dictionary<string, string>>();

    // We now know how many rows are in the field group. Assemble the ordered list of values for each field.
    for (int curRow = 1; curRow <= highestRow; curRow++)
    {
        var valuesForThisRow = new Dictionary<string, string>();

        foreach (var fieldName in fieldGroupFields)
        {
            valuesForThisRow[fieldName] = ""; // If this field does not have a row assigned, it will be blank for this row

            var rowNumbers = fvc.GetFieldRowNumbers(fieldName);

            // Find the value for this field in this row (might not exist)
            for (int rowNumIdx = 0; rowNumIdx < rowNumbers.Count; rowNumIdx++)
            {
                if (rowNumbers[rowNumIdx] != curRow)
                    continue; // skip value from another row

                var fieldValuesObj = fvc[fieldName];

                if (fieldValuesObj == null)
                    continue; // no values for this field
                                    
                // Make sure we are using an array
                if (!(fieldValuesObj is object[]))
                    fieldValuesObj = new object[] { fieldValuesObj };

                object[] fieldValuesArray = (object[])fieldValuesObj;

                valuesForThisRow[fieldName] = (fieldValuesArray[rowNumIdx]).ToString();
            }
        }

        valuesForAllRows.Add(valuesForThisRow);
    }

    // TODO: This is where you can output the ordered field values from valuesForAllRows
}

 

4 0
replied on April 18, 2023

Hello Robert,

Thanks for provided code and its working fine but for some records it was not worked as expected due to row number not properly arranged or any reason behind it.

 

Please find the updated code which is working fine for me and again thanks for help.

 //code here

                           // EntryInfo entry = Entry.GetEntryInfo(entryId, session);
                            FieldValueCollection fvc1 = myEntry.GetFieldValues();


                            // This rows is my required so that can help to count max rows
                            object FieldRuleMakingStageValues = myEntry.GetFieldValue("Rulemaking Stage");

                            object[] objFieldRuleMakingStageValues = null;
                            if (FieldRuleMakingStageValues is Array)
                            {
                                objFieldRuleMakingStageValues = (object[])FieldRuleMakingStageValues;
                            }
                            else
                            {
                                objFieldRuleMakingStageValues = new object[1];
                                objFieldRuleMakingStageValues[0] = FieldRuleMakingStageValues;
                            }

                            //
                            List<int> multivalueFieldGroupIds = new List<int>();

                            // Find all multivalue field groups for this entry (usually only one is defined on a template)
                            foreach (var fieldName in fvc1.FieldNames)
                            {
                                int groupId = fvc1.GetFieldGroupId(fieldName);
                                if (groupId > 0 && !multivalueFieldGroupIds.Contains(groupId))
                                    multivalueFieldGroupIds.Add(groupId);
                            }

                            // Loop over the multivalue field groups (usually only one is defined on a template)
                            foreach (var groupId in multivalueFieldGroupIds)
                            {
                                List<string> fieldGroupFields = new List<string>();

                                // Find the fields in this multivalue field group
                                foreach (var fieldName in fvc1.FieldNames)
                                {
                                    if (fvc1.GetFieldGroupId(fieldName) != groupId)
                                        continue; // Belongs to a different field group
                                }

                //checking max row 
                                int highestRow = 0;
                                if(objFieldRuleMakingStageValues != null)
                                {
                                    highestRow = objFieldRuleMakingStageValues.Count();
                                }
                //end of checking max row

                                //else
                                //{

                                //}
                                //int highestRow = fvc1.GetHighestRowNum(1);// 0;

                                //// Calculate how many rows are in the multivalue field group for this entry
                                //foreach (var fieldName in fieldGroupFields)
                                //{
                                //    var rowNumbers = fvc1.GetFieldRowNumbers(fieldName);

                                //    if (rowNumbers == null)
                                //        continue;

                                //    foreach (var rowNumber in rowNumbers)
                                //        highestRow = Math.Max(highestRow, rowNumber);
                                //    //    highestRow = rowNumbers.Count();
                                //}

                                var valuesForAllRows = new List<Dictionary<string, string>>();

                                // We now know how many rows are in the field group. Assemble the ordered list of values for each field.
                                for (int curRow = 1; curRow <= highestRow; curRow++)
                                {
                                    var valuesForThisRow = new Dictionary<string, string>();

                                    foreach (var fieldName in fieldGroupFields)
                                    {
                                        valuesForThisRow[fieldName] = ""; // If this field does not have a row assigned, it will be blank for this row

                                        List<int> rowNumbers = new List<int>();
                                        if(highestRow == 1)
                                        {
                                            rowNumbers = fvc1.GetFieldRowNumbers(fieldName);
                                            if (rowNumbers[0].ToString() == "0")
                                            {
                                                rowNumbers.Clear();
                                                rowNumbers.Add(1);
                                            }
                                            else
                                            {
                                               // rowNumbers - do nothing
                                            }
                                            
                                        }
                                        else
                                        {
                                            //var rowNumbers = fvc1.GetFieldRowNumbers(fieldName);
                                             rowNumbers = fvc1.GetFieldRowNumbers(fieldName);
                                            for( int k=0;k<1;k++)
                                            {
                                                if (rowNumbers[k].ToString() == "0")
                                                {
                                                   // rowNumbers.Clear();
                                                    rowNumbers[k] = 1;//.Add(1);
                                                }
                                                else
                                                {
                                                    // rowNumbers - do nothing
                                                }
                                            }
                                        }
                                        

                                        // Find the value for this field in this row (might not exist)
                                        for (int rowNumIdx = 0; rowNumIdx < rowNumbers.Count; rowNumIdx++)
                                        {
                                           // if (rowNumbers[rowNumIdx] != curRow)
                                              //  continue; // skip value from another row

                                            var fieldValuesObj = fvc1[fieldName];

                                            if (fieldValuesObj == null)
                                                continue; // no values for this field

                                            // Make sure we are using an array
                                            if (!(fieldValuesObj is object[]))
                                                fieldValuesObj = new object[] { fieldValuesObj };

                                            object[] fieldValuesArray = (object[])fieldValuesObj;

                                            if (fieldValuesArray.Length > (curRow - 1))
                                               if(!string.IsNullOrEmpty(Convert.ToString(fieldValuesArray[curRow-1])))
                                                     valuesForThisRow[fieldName] = (fieldValuesArray[curRow-1]).ToString();
                                               else
                                                   valuesForThisRow[fieldName] = "";
                                            else
                                                valuesForThisRow[fieldName] = "";
                                            //valuesForThisRow[fieldName] = (fieldValuesArray[rowNumIdx]).ToString();
                                        }
                                    }

                                    valuesForAllRows.Add(valuesForThisRow);
                                }

//end of code

0 0
SELECTED ANSWER
replied on April 18, 2023

sample code attached if having some issue to read it

0 0
replied on April 19, 2023

The sample code does not populate fieldGroupFields, so the loop that populates valuesForThisRow is never entered. I assume this is a modified snippet from the code that works for some values?

0 0
replied on April 19, 2023

Yes , I had modified code that works for some values.

I have changed as per my need.

Thanks,

Pratik 

 

0 0
replied on April 10, 2023

I vaguely recall multi-value field groups and the SDK having some weirdness with the SDK setting values as NULL and client applications setting them as blank (empty string ""), or vis versa. That might be a part of the issue you're seeing.

I unfortunately don't have a solution offhand though.

0 0
replied on April 14, 2023

Thank you Samuel.

I am in communication with LF team and will update you if anything found.

Regards,

Pratik 

1 0
replied on July 30, 2023

Hello Team,

I am able to getting metadata from mutli-value group field. But I have requirement where need to updates metadata of specific group field. I have posted requirement in below link.

https://answers.laserfiche.com/questions/210647/Multivalue-group-fields-update-problem-using-laserfiche-sdk

Please help me our for laserfiche sdk code.

Thanks,

pratik

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

Sign in to reply to this post.