1

I am trying to fetch items of a particular view using JSOM using below code:

ListDataService.getItemsByCamlQueryUsingCSOM = function (listName, camlQuery, viewfields) {
        var deferred = $.Deferred();
        var context = SP.ClientContext.get_current();
        var web = context.get_web();
        var list = web.get_lists().getByTitle(listName);
        var query = new SP.CamlQuery();
        query.set_viewXml(camlQuery);
        var items = list.getItems(query);

        var index = viewfields.indexOf("LinkTitle");
        if (index !== -1) {
            viewfields[index] = "Title";
        }
        context.load(items, "Include(" + viewfields.join() + ")");
        //context.load(items);
        context.executeQueryAsync(function () {
            deferred.resolve(items);
        }, function (sender, args) {
            deferred.reject(args);
        });
        return deferred.promise();
    }

I get a strange behaviour that if my viewfields has any Managed metadata field, the executeQueryAsync is mostly failing with below error "Value does not fall within the expected range"

 at Microsoft.SharePoint.SPFieldMap.GetColumnNumber(String strFieldName, Boolean bThrow)
↵   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.GetValue(String strName, Boolean bThrowIfValueMissing, Boolean bThrowIfFieldMissing)
↵   at Microsoft.SharePoint.SPListItem.GetFieldValue_Client(String fieldName)
↵   at Microsoft.SharePoint.Client.ServerStub.WriteAsJson(JsonWriter writer, Object obj, ClientObjectQuery objectQuery, ProxyContext proxyContext)
↵   at Microsoft.SharePoint.Client.ServerStub.WriteChildItems(JsonWriter writer, Object obj, ClientObjectQuery objectQuery, ProxyContext proxyContext)
↵   at Microsoft.SharePoint.Client.ServerStub.WriteAsJson(JsonWriter writer, Object obj, ClientObjectQuery objectQuery, ProxyContext proxyContext)
↵   at Microsoft.SharePoint.Client.ServerStub.WriteAsJsonWithMonitoredScope(JsonWriter writer, Object value, ClientObjectQuery objectQuery, ProxyContext proxyContext)
↵   at Microsoft.SharePoint.Client.ClientMethodsProcessor.WriteQueryResults(Object obj, ClientObjectQuery objQuery)
↵   at Microsoft.SharePoint.Client.ClientMethodsProcessor.ProcessQuery(XmlElement xe)
↵   at Microsoft.SharePoint.Client.ClientMethodsProcessor.ProcessOne(XmlElement xe)
↵   at Microsoft.SharePoint.Client.ClientMethodsProcessor.ProcessStatements(XmlNode xe)
↵   at Microsoft.SharePoint.Client.ClientMethodsProcessor.Process()

My viewfields has only 3 or 4 fields and I tried to hard code only the Managed metadata field in the Include statement and still it threw the same error.

Configuration of my site:

  1. List is having 30+ columns
  2. Listview Look up threshold is 8 for the web application.
  3. Site Regional setting has Local set to English(South Africa) (PS: Setting it to English(US) did not make any difference.)

Update: Got this issue fixed by adding the viewfields in caml instead of Include .

  • Same behavior if you specify the viewfields in the caml instead of Include? – Anders Aune Aug 9 '16 at 13:46
  • @AndersAune Thanks for your suggestion it works always when I add it as ViewFields in caml. Strange but works for now. Please write it as answer so that I can upvote and mark it as answer. :-) – Unnie Aug 11 '16 at 14:19
1

The hidden fields connected to the managed metadata fields could be the culprit. If you have a look at Vadims answer in this question he says:

The main difference that ViewFields query option also includes system columns.

So try using <ViewFields /> in the CamlQuery instead of Include

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.