Author field in Discussion List not found

09/02/2016 08:51

In one of our project we needed to customize Discussion List of Community site.


When calling obvious code with item["Author"], we got exception Value doesn't fall in expected range
 In UI, field was there, had value, we can read it in PowerShell, but unable to read it in code inside ElevatedPrivileges.
 This happened after adding custom fields to Discussion list, for exapmle Managed metadata field or field of type Person. When
 added text or number field, no error occured.
 Strange, ... after lot of struggling, we found following workaround..
 - We needed to change LookupField property of Author field, then Author field was readable in elevated privileges after adding taxonomy field.
private static string lookupIdPropertyName = "NameWithPicture";

private static void UpdateAuthorField(SPList list)
 SPFieldUser field = list.Fields.TryGetFieldByStaticName("Author") as SPFieldUser;
 if (field.LookupField != lookupIdPropertyName)
  field.LookupField = lookupIdPropertyName;