-1

I have the following CAML query which works perfectly:

var emergencyCAML = "<View><Query><Where><And><Contains><FieldRef Name='Project_x0020_Members'/><Value Type='Note'>" + searchTerms[0] + "</Value></Contains><Contains><FieldRef Name='Project_x0020_Members'/><Value Type='Note'>" + searchTerms[1] + "</Value></Contains></And></Where><OrderBy><FieldRef Name='Title' Ascending='TRUE' /></OrderBy></Query></View>";

However, When I add the notIncludes it doesn't bring any results.

var emergencyCAML = "<View><Query><Where><And><Contains><FieldRef Name='Project_x0020_Members'/><Value Type='Note'>" + searchTerms[0] + "</Value></Contains><Contains><FieldRef Name='Project_x0020_Members'/><Value Type='Note'>" + searchTerms[1] + "</Value></Contains><NotIncludes><FieldRef Name = 'Hidden' LookupId='True'/><Value Type = 'Lookup'>" + _spPageContextInfo.userId + "</Value><XML /></NotIncludes></And></Where><OrderBy><FieldRef Name='Title' Ascending='TRUE' /></OrderBy></Query></View>";

1 Answers1

1

Each element can only contain two child elements. Your version with the not includes violates that. Try fixing it by wrapping the in another tag to ensure the first And only has two direct child elements. Like this:

<View>
<Query>
    <Where>
        <And>
            <And>                   
                <Contains><FieldRef Name='Project_x0020_Members'/><Value Type='Note'>" + searchTerms[0] + "</Value></Contains>
                <Contains><FieldRef Name='Project_x0020_Members'/><Value Type='Note'>" + searchTerms[1] + "</Value></Contains>
            </And>
            <NotIncludes><FieldRef Name = 'Hidden' LookupId='True'/><Value Type = 'Lookup'>" + _spPageContextInfo.userId + "</Value><XML /></NotIncludes>
        </And>
    </Where>
    <OrderBy><FieldRef Name='Title' Ascending='TRUE' /></OrderBy>
</Query>
</View>

More info: https://msdn.microsoft.com/en-us/library/office/ms196939.aspx

Remarks This element can be nested inside other And and Or elements. The server supports unlimited complicated queries. However, any given And element can have only two conjuncts; that is, only two child elements. If you need to conjoin three or more conditions, you must nest the And elements, as demonstrated by the third example in the following section.

Shel
  • 64
  • 5
  • It didn't work for me, but good to know. I solved the issue another way already. I just used jquery to do the additional filtering on the returned items. – 贝壳 - BeiKe Nov 17 '17 at 15:14