SharePoint 2013 Custom list field iterator not saving values for MultiLine or person columns

886 views Asked by At

I have a custom field iterator that was working fine on my custom SharePoint form in 2010. However, in SharePoint 2013, it is not saving values for MultiLine and people columns. Fow all other columns (text, number, choice...etc) it saves the value fine. here is what i have:

 protected void btnSave_Expense(object p_sender, EventArgs p_e)
   {

       SPListItem item = // Get SPListItem
       saveCustomFields (listitem);
    };


   private void saveCustomFields(SPListItem listitem)
    {
        for (int i = 0; i < listitem.Fields.Count; i++)
        {
            string fieldname = listitem.Fields[i].StaticName;
            if (!Enumerable.Contains(SPConstants.EtravelAndExpense_fields.ToArray(), fieldname))
            {
                FormField formField = ExtensionMethods.GetControlsOfType<FormField>(ListFieldIterator1.Controls).Where(f => f.FieldName == fieldname).FirstOrDefault();

                if (formField != null)
                {
                    object obj = formField.ItemFieldValue; //returns values for all fields except multiline or people.
                    listitem[fieldname] = obj;
                }
            }
        }
    }

// Inside ExtensionMethods class

public static List<T> GetControlsOfType<T>(this ControlCollection controls)
  {
        List<T> resultList = new List<T>();
        foreach (Control control in controls)
        {
            if (control is T)
                resultList.Add((T)((object)control));
            if (control.Controls.Count > 0)
            {
                resultList.AddRange(GetControlsOfType<T>(control.Controls));
            }
        }
        return resultList;
    }

//SPConstants array fields.

public static string[] EtravelAndExpense_fields = new string[]
  {
        "Name",
        "Title",
        "Test",
         ..... //more fields
  };

formField.ItemFieldValue for columns of type multiline or person/people return null. Help please!!

1

There are 1 answers

2
Life is good On BEST ANSWER

I had to get the values of the custom fields of type multi-line or person/people on the client side first and then save them to a hidden field that i access on the server. I am not sure why this behavior takes place on SharePoint 2013 and only for multi-line or person/people, but this workaround solved the issue.