SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am getting the error on the following line for a timer job:

if (listItem["Department"] != null)

Normally this error indicates that it cannot find the field, but there are no spaces and the field label name and strong name are the same. Furthermore, if I write it like this:

if (listItem.Fields["Department"] != null)

I no longer get the error.

The problem is I am trying to call TaxonomyFieldValueCollection on the object and cannot call it by Fields. Is there some nuanced difference between the two that I'm missing that's causing this error?

EDIT: I figured out the problem. I had set query.ViewFieldsOnly = true; and "Department" was a new field and was not set in the ViewFields, so as far as the timer job could tell the field didn't exist. I simply needed to add the field into the list of fields in ViewField.

share
    
If you've resolved this, please post your solution as an answer for future visitors. – RJ Cuthbertson Feb 10 '13 at 16:06
    
I tried to do this before but was blocked from posting an answer. I can do it now it seems. – user11457 Feb 12 '13 at 18:58
up vote 3 down vote accepted

I figured out the problem. I had set query.ViewFieldsOnly = true; and "Department" was a new field and was not set in the ViewFields, so as far as the timer job could tell the field didn't exist. I simply needed to add the field into the list of fields in ViewField.

share|improve this answer
    
What do you mean by in ViewField? – Shane Courtrille Jul 4 '13 at 18:05

The first line checks if the value of the data in the column "Department" is null for that specific list item.

The second line checks if the SPField object "Department" is null.

If the SPField exists on the list, it should never be null, but the data stored in that field for a specific list item may be.

share|improve this answer
    
It's not that the line is resolving incorrectly, it's that there is an exception and gives the "value does not fall within the expected range" error. Please ignore the "if" statement, I am talking purely about the behavior of getting the value of the list item. The SPField line was just an example to show that the value can be pulled with the name "Department". – user11457 Jan 28 '13 at 16:53
    
Does the field happen to have a different internal field name? – RJ Cuthbertson Jan 28 '13 at 18:08

This error System.ArgumentException: Value does not fall within the expected range with exception message Microsoft.SharePoint.SPFieldMap.GetColumnNumber(String strFieldName, Boolean bThrow) is due to throttling limit set at List View Lookup Threshold settings in WebApplication.

To resolve this error, Open the SharePoint Central Administration site and click “Manage Web Application” link located under Application Management Group. Select the web application that has the problem. Select the “Resource Throttling” link under the “General Settings”

Navigate to List View Lookup Threshold section and change the value to a higher value depending on the count of Lookup, Person/Group, or workflow status field available in the list that caused the issue.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.