我有以下CAML查询,效果很好:
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>";
然而, 当我添加notIncludes时,它不会带来任何结果。
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>";
答案 0 :(得分:1)
每个元素只能包含两个子元素。您的不包含的版本违反了该规定。尝试通过包装另一个标签来确保第一个并且只有两个直接子元素来修复它。像这样:
<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>
更多信息:https://msdn.microsoft.com/en-us/library/office/ms196939.aspx
备注 此元素可以嵌套在其他And和Or元素中。服务器支持无限复杂的查询。但是,任何给定的And元素只能有两个合取;也就是说,只有两个子元素。如果需要连接三个或更多条件,则必须嵌套And元素,如下一节中的第三个示例所示。