Note that there are some explanatory texts on larger screens.

plurals
  1. POGet value from SPFieldUser with AllowMultipleValues fails only in a Timer Job
    primarykey
    data
    text
    <p>This one is weird.</p> <p>I'm executing this code in a Timer Job in SharePoint 2010 ...</p> <pre><code>... // Get the field by it's internal name SPField field = item.Fields.GetFieldByInternalName(fieldInternalName); if (field != null) { SPFieldUser userField = (SPFieldUser)field; object value = null; if (userField.AllowMultipleValues) { // Bug when getting field value in a timer job? Throws an ArgumentException users = new SPFieldUserValueCollection(item.ParentList.ParentWeb, item[userField.Id].ToString()); } else { // Get the value from the field, no exception value = item[userField.Id]; } } ... </code></pre> <p>This code works perfectly when run in a simple ConsoleApplication but when run in the context of a Timer Job in SharePoint 2010 it throws an ArgumentException in the line ...</p> <pre><code>users = new SPFieldUserValueCollection(item.ParentList.ParentWeb, item[userField.Id].ToString()); </code></pre> <p>I've tried many variations to retreive a value from a SPFieldUser but all fail only when a Timer Job is executing it and the field has AllowMultipleValues property set to TRUE.</p> <p>I have tried debugging with Reflector and it seems that the exception is being thrown here in SPListItem ...</p> <pre><code>public object this[Guid fieldId] { get { SPField fld = this.Fields[fieldId]; if (fld == null) { throw new ArgumentException(); } return this.GetValue(fld, -1, false); } ... </code></pre> <p>And this here would be the exception stack trace...</p> <pre><code>System.ArgumentException was caught Message=Value does not fall within the expected range. Source=Microsoft.SharePoint StackTrace: at Microsoft.SharePoint.SPFieldMap.GetColumnNumber(String strFieldName, Boolean bThrow) at Microsoft.SharePoint.SPListItemCollection.GetColumnNumber(String groupName, Boolean bThrowException) at Microsoft.SharePoint.SPListItemCollection.GetRawValue(String fieldname, Int32 iIndex, Boolean bThrow) at Microsoft.SharePoint.SPListItem.GetValue(SPField fld, Int32 columnNumber, Boolean bRaw, Boolean bThrowException) at Microsoft.SharePoint.SPListItem.get_Item(Guid fieldId) at FOCAL.Point.Applications.Audits.AuditUtility.GetPeopleFromField(SPListItem item, String fieldInternalName) </code></pre> <p>Sighh... any thoughts?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload