0

I'm trying to use CAML query with In operator since it's easyer to build then Or conditions.

Here is my CAML

    <View Scope="RecursiveAll">
<Query>
<Where>
<In>
<FieldRef Name="Title" />
<values>
    <Value Type="Text">A1</Value>
    <Value Type="Text">NPD</Value>
    <Value Type="Text">NPD2</Value>
</values>
</In>
</Where>
</Query>
</View>

Unfortunately it returns nothing but if I search the values one by one it works. What is my mistake?

Here is the complete CSOM code

var xmlQuery = '<View Scope="RecursiveAll"><Query><Where><In><FieldRef Name="Title" /><values>';
        $("select[title='Perf Decl selected values'] option").each(function(){
            xmlQuery += '<Value Type="Text"><![CDATA[' + this.text + ']]></Value>'; 
        });
        var context = SP.ClientContext.get_current();
        var web = context.get_web();
        var lists = web.get_lists(); 
        var listId = "BEE6E734-9B7D-4852-ACE2-E641D6EDE2A3";// perf decl list
        var list = lists.getById(listId);
        var query=new SP.CamlQuery();
        xmlQuery += '</values></In></Where></Query></View>';
        alert( xmlQuery  );
        query.set_viewXml(xmlQuery);
        resultsPD = list.getItems(query);
        context.load(resultsPD);
        context.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceededPerfDecl), Function.createDelegate(this, this.onQueryFailedPerfDecl)); 

        function onQueryFailedPerfDecl(sender, args) {
        alert('Request PerfDecl failed. ' + args.get_message() + '\n' + args.get_stackTrace());
        flag = false;
    }

    function onQuerySucceededPerfDecl(sender, args) {
    alert('succed');
        var listItemInfo = '';
        var listItemEnumerator = resultsPD.getEnumerator();

        var cptR = 0;
        while (listItemEnumerator.moveNext()) {
            if(cptR  == 0){
                tabPerf += "<table>";
            }
            var oListItem = listItemEnumerator.get_current();
            tabPerf += "<tr><td>" + oListItem.get_item('Title') +"</td><td>" + oListItem.get_item('Perf_x0020_Decl') + "</td></tr>";
            alert('movenex');
            cptR++;
        }
        if(cptR  > 0){
            tabPerf += "</table>";
        }else{
            tabPerf += "";
        }
        $("input[title='PerfDeclTab']").val(tabPerf);
        flag = true;
        alert("tabPerf  == " + tabPerf);
        return flag;
    }
2

CAML schema is case-sensitive. You need to change <values> to <Values>.

In general all elements are capitalized, but for some reason there are elements like <CHOICES> written in uppercase. When in doubt, best reffer to Collaborative Application Markup Language (CAML) schemas on MSDN.

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.