2

I have a list with a relatively large number of person columns in SharePoint Online and am having an issue where I am able to query certain person columns but not others and am unable to come up with an explanation about why or how to solve this.

I am aware that SharePoint Online imposes a limit on the number of lookups/person columns that can be retrieved in a single query, but I am having this issue even if I try to query a single column.

In order to reproduce the issue and illustrate what I am doing, I have made this function:

function queryList(queryValue, selectColumn) {
    var context = SP.ClientContext.get_current();
    var list = context.get_web().get_lists().getByTitle('Teams');

    var camlQuery = new SP.CamlQuery();
    var viewXml = `<View Scope='RecursiveAll'>
        <Query>
          <Where>
            <Eq><FieldRef Name='MfgLoc' /><Value Type='Text'>${queryValue}</Value></Eq>
          </Where>
        </Query>
    </View>`;
    camlQuery.set_viewXml(viewXml);

    var listItems = list.getItems(camlQuery);
    context.load(listItems, `Include(${selectColumn})`);

    context.executeQueryAsync(
        () => console.log('done'),
        (_, e) => console.error(e.get_message())
    );
}

This basically just queries the list, filtering a single text column on a single value, and retrieving one column.

For certain columns, this works fine:

queryList('NY', 'LOGISTICS_x002d_PP');   // completes successfully

For others, it doesn't:

queryList('NY', 'DISTRIBUTION_x002d_PP');

The latter fails with an unhelpful SharePoint internal error: Value does not fall within the expected range.

I have also observed that if I filter the query such that it doesn't match any rows, it completes without error, even when trying to retrieve the same column:

queryList('NF', 'DISTRIBUTION_x002d_PP');   // completes successfully because no rows have an MfgLoc of NF

There seems to be no significant difference between the columns where this succeeds vs. the ones where it fails except that it seems that it succeeds for the first nine person columns that were originally created in the list and fails for all other person columns (so, the 10th person column created and onwards).

Querying these columns using Lists.asmx or the REST API works just fine, but fails in JSOM no matter what I do.

Has anyone else run across this issue?

1

The cause:

It turns out that the 12-lookup-column limit was the culprit here, even though I was only trying to query one column.

There is some detail about this limitation in Microsoft's online documentation:

List view lookup threshold

Specifies the maximum number of joins allowed per query, such as those based on lookup, person/group, or workflow status columns. If the query uses more than [twelve] joins, the operation is blocked. This does not apply to single item operations. When using the maximal view via the object model (by not specifying any view fields), SharePoint will return up to the first 12 lookups.

Note: After applying the SharePoint Server 2013 cumulative update package released on August 13, 2013 (https://support.microsoft.com/en-us/kb/2817616), the default value is increased from 8 to 12.

The problem was that I was not specifying a <ViewFields> element in my query, so as indicated above, the internal query returned the first 12 lookups/person columns, and then my Include(...) string was indicating a column that wasn't included in the query results. So the error was coming from trying to obtain a column that wasn't in the query results. (My list in this case had 3 lookup columns in addition to the person columns, so that explains why I had an issue after the 9th person column).

The solution:

Explicitly specify a <ViewFields> element in the query's ViewXml. In terms of the example code above, that would look like this:

var viewXml = `<View Scope='RecursiveAll'>
    <Query>
      <Where>
        <Eq><FieldRef Name='MfgLoc' /><Value Type='Text'>${queryValue}</Value></Eq>
      </Where>
    </Query>
    <ViewFields><FieldRef Name='${selectColumn}' /></ViewFields>
</View>`;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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