开发者

CAML Query find records where parameter does not exist?

开发者 https://www.devze.com 2022-12-11 20:35 出处:网络
I have a sharepoint list which has several fields.It seems that when a field is left blank on one of the records - that attribute is missing on the field when I query the list using a CAML Query.

I have a sharepoint list which has several fields. It seems that when a field is left blank on one of the records - that attribute is missing on the field when I query the list using a CAML Query.

Is it possible to write a query to return the records which do not contain this attribue?

Example:

id Employee Title description
-------------------------
1  Jeff  Person1 
2  Bob  Person2
3  Charles Person3
4    Person4
5    Person5

Is there any way to query this to only return records with id 4 and 5 because they have left the name field blank?

I tried the following:

System.Text.StringBuilder xmlQuery = new StringBuilder();
xmlQuery.Append("<Query&g开发者_如何学Pythont;");        
xmlQuery.Append("   <Where>");        
xmlQuery.Append("       <IsNull>");            
xmlQuery.Append("           <FieldRef Name=\"Employee Title\" />");           
xmlQuery.Append("       </IsNull>");        xmlQuery.Append("   </Where>");        
xmlQuery.Append("</Query>");        XmlNode query = new XmlDocument();          
query.InnerXml = xmlQuery.ToString();

But of course the attribute doesn't exist in those records, so nothing is returned

Thanks in advance!


Edit

The query works after replacing any spaces in the Name with x0020

xmlQuery.Append("           <FieldRef Name=\"Employee_x0020_Title\" />");


There should not be any issue if a field value is missing one or more fields, it is just normal and should work. But one change you will have to do in the query is to remove the outer query tag please use the below query and you should be good to go.

<Where>       
<IsNull>           
<FieldRef Name="Name" />       
</IsNull>   
</Where>


This is a longshot, but is your "Name" column actually named "Title" within the list?

FieldRefs expect the internal name of the field AFAIK

0

精彩评论

暂无评论...
验证码 换一张
取 消