3

I had a problem with using Contain filter in CAML query in csom, this is my code :

var siteUrl = "/rp/lab/ssite";
var listname = "listview";
var clientContextSO = new SP.ClientContext(siteUrl);
var oListSO = clientContextSO.get_web().get_lists().getByTitle(listname);
var camlQuerySO = new SP.CamlQuery();
camlQuerySO.set_viewXml('<View><Query><ViewFields><FieldRef Name="ID"/><FieldRef Name="Title" /></ViewFields>\
                    <Where>\
                        <Contain>\
                            <FieldRef Name="column1"/>  \
                            <Value Type="Text">aa</Value>\
                        </Contain>\
                    </Where>\
                        </Query><RowLimit>100</RowLimit></View>');
var collListItemSO = oListSO.getItems(camlQuerySO);
clientContextSO.load(collListItemSO);
clientContextSO.executeQueryAsync(Function.createDelegate(this, function (sender, args) {
    var listItemEnumeratorSO = collListItemSO.getEnumerator();
    while (listItemEnumeratorSO.moveNext()) {
        var olistItemEnumeratorSO = listItemEnumeratorSO.get_current();
        console.log(olistItemEnumeratorSO.get_item('Title'));
    }
}), Function.createDelegate(this, function (sender, args) {
    console.log('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}));

This code works fine with Eq filter but When i use Contain this error happened :

Value does not fall within the expected range.
  • 2
    Shouldn't it be Contains rather than Contain – Nadeem Yousuf Jul 9 '17 at 5:48
  • @NadeemYousuf Exactly ! worked ! because of stupid error with out any explanation I can not find out what this is about ! thanks. – alireza Jul 9 '17 at 7:12
  • Added it as answer. – Nadeem Yousuf Jul 9 '17 at 7:50
4

Use Contains instead of Contain in the CAML query.

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.