IsNull with other parms in CAML query for SharePoint 2010 - sharepoint-2010

Consider the folowing CAML query:
<Query>
<Where>
<And>
<Eq>
<FieldRef Name="Field1"/>
<Value Type="Text">Field value 1</Value>
</Eq>
<Eq>
<FieldRef Name="Field2"/>
<Value Type="Text">Field value 2</Value>
</Eq>
<IsNull>
<FieldRef Name="Field3"/>
</IsNull>
</And>
</Where>
SharePoint raises a Microsoft.SharePoint.SoapServer.SoapServerException. What is the problem here?

The "And" element can have only two child elements. So your query could, for example, have this structure, where "And" has "IsNull" plus a nested "And" as child elements.
<Query>
<Where>
<And>
<IsNull>
<FieldRef Name="Field3" /></IsNull>
<And>
<Eq>
<FieldRef Name="Field1" /><Value Type="Counter">field 1 value</Value>
</Eq>
<Eq>
<FieldRef Name="Field2" /><Value type="Text">field 2 value</Value>
</Eq>
</And>
</And>
</Where>
This article has some good examples: http://msdn.microsoft.com/en-us/library/ms196939.aspx

Related

CAML Query with IN + AND or other

My question is about caml query SP2010,
i've got colums as follow: Country, Role, Species, Species, Topic, Documenttype, Searchtext.
There is possible that user will search by Countries (multiple->UK,France,Belgium) and type document name like Doc_num_one.txt and add other criteria like Role, Species, Species, Topic, Documenttype. I've tried different queries but I think I stucked.
Below what I tried so far:
<Query>
<Where>
<In>
<FieldRef Name="Country"/>
<Values>
<Value Type="Lookup">United Kingdom</Value>
<Value Type="Lookup">Poland</Value>
<Value Type="Lookup">Belgium</Value>
</Values>
</In>
</Where>
</Query>
or
<Query>
<Where>
<And>
<Eq>
<FieldRef Name="Title" />
<Value Type="Text">doc num two</Value>
</Eq>
<Or>
<And>
<Eq>
<FieldRef Name="Country" />
<Value Type="Lookup">United Kingdom</Value>
</Eq>
<Eq>
<FieldRef Name="Role" />
<Value Type="Lookup">Super Admin</Value>
</Eq>
</And>
<And>
<Eq>
<FieldRef Name="Country" />
<Value Type="Lookup">Belgium</Value>
</Eq>
<Eq>
<FieldRef Name="Role" />
<Value Type="Lookup">Super Admin</Value>
</Eq>
</And>
<And>
<Eq>
<FieldRef Name="Country" />
<Value Type="Lookup">Poland</Value>
</Eq>
<Eq>
<FieldRef Name="Role" />
<Value Type="Lookup">Super Admin</Value>
</Eq>
</And>
</Or>
</And>
</Where>
</Query>
Solution:
<Query>
<Where>
<And>
<In>
<FieldRef Name="Country"/>
<Values>
<Value Type="Lookup">United Kingdom</Value>
<Value Type="Lookup">Poland</Value>
<Value Type="Lookup">Belgium</Value>
</Values>
</In>
<In>
<FieldRef Name="Role"/>
<Values>
<Value Type="Lookup">Super Admin</Value>
<Value Type="Lookup">Admin</Value>
<Value Type="Lookup">User</Value>
</Values>
</In>
</And>
</Where>
</Query>
The second query does not work because it has more than two child elements within the <Or> element. If you want to test more sub-conditions, you have to introduce helper elements:
<Or>
<And>...</And>
<And>...</And>
<And>...</And>
<And>...</And>
<And>...</And>
</Or>
becomes
<Or>
<And>...</And>
<Or>
<And>...</And>
<Or>
<And>...</And>
<Or>
<And>...</And>
<And>...</And>
</Or>
</Or>
</Or>
</Or>
The same applies to <And> elements.

Alex the CAML Query has "NO RESULTS"

My SharePoint 2010 CAML Query is not returning the expected results. It is returning nothing. What am I doing wrong?
<View>
<Query>
<Where>
<In>
<FieldRef ID="1d8376f2-5ac6-407f-9652-a74405a87846" Name="Bank_x0020_Choice" />
<Values>
<Value Type="Choice">Retail</Value>
<Value Type="Choice">Commercial</Value>
</Values>
</In>
</Where>
</Query>
<ViewFields>
<FieldRef ID="1d22ea11-1e32-424e-89ab-9fedbadb6ce1" Name="ID" />
<FieldRef ID="fa564e0f-0c70-4ab9-b863-0177e6ddd247" Name="Title" />
<FieldRef ID="1d8376f2-5ac6-407f-9652-a74405a87846" Name="Bank_x0020_Choice" />
<FieldRef ID="224ba411-da77-4050-b0eb-62d422f13d3e" Name="LinkFilename2" />
</ViewFields>
<RowLimit Paged="TRUE">1000</RowLimit>
</View>
Try to use the tool CAML Builder. With this tool you can check your CAML queries with no pre-configuration and no coding. There you can test your query, maybe there is simply an spelling error in your fieldrefs, values or names.

CAML : Cannot complete this action

It seems my following query is failing and throwing "Cannot complete this action".However when I test this query in CAML Query builder it's working fine.
<Where>
<And>
<Or>
<Eq><FieldRef Name='Participant' /><Value Type='User'>Test1</Value></Eq>
<Eq><FieldRef Name='Participant' /><Value Type='User'>Test2</Value></Eq>
<Eq><FieldRef Name='Participant' /><Value Type='User'>Test3</Value></Eq>
</Or>
<Eq><FieldRef Name='Department' /><Value Type='Text'>Positioning</Value></Eq>
</And>
</Where>
Its seem to your query there are more than two condition on <OR> tab.You can only have a maximum of two conditions within an <Or> or an <And> tag.
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.
please see here : MSDN
So you would need to rewrite your query like:
<Where>
<And>
<Or>
<Eq>
<FieldRef Name='Participant' />
<Value Type='User'>Test1</Value>
</Eq>
<Or>
<Eq>
<FieldRef Name='Participant' />
<Value Type='User'>Test2</Value>
</Eq>
<Eq>
<FieldRef Name='Participant' />
<Value Type='User'>Test3</Value>
</Eq>
</Or>
</Or>
<Eq>
<FieldRef Name='Title' />
<Value Type='Text'>Postiioning</Value>
</Eq>
</And>
</Where>

filtering in sharepoint caml

Below I have the view which i have in the list schema.The issue is that it never picks the where clause.It displays the order by clause correctly when I go to modify the view but not the where clause which should show up in the filter section.I also tried ceating a view in UI and then through sharepoint manager got the schema and then created a view but still does not work.Am I doing something wrong here.
<View BaseViewID="1" Type="HTML" WebPartZoneID="Main" DisplayName="Tab 1" DefaultView="FALSE" MobileView="TRUE" MobileDefaultView="FALSE" SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/images/generic.png" Url="T1.aspx">
<Toolbar Type="Standard" />
<XslLink Default="TRUE">main.xsl</XslLink>
<RowLimit Paged="TRUE">30</RowLimit>
<Query>
<OrderBy Override="TRUE">
<FieldRef Name="Test1" />
<FieldRef Name="Test2" />
</OrderBy>
<Where>
<Eq>
<FieldRef Name="Test3"/>
<Value Type="Text">1</Value>
</Eq>
</Where>
</Query>
<ViewFields>
<FieldRef Name="Attachments"></FieldRef>
<FieldRef Name="LinkTitle"></FieldRef>
<FieldRef Name="Test1"></FieldRef>
<FieldRef Name="Test2"></FieldRef>
<FieldRef Name="Test3"></FieldRef>
<FieldRef Name="Audience"></FieldRef>
</ViewFields>
<ParameterBindings>
<ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
<ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_DEFAULT)" />
</ParameterBindings>
</View>
Try to Put Where clause before the Order By Clause.
I am not 100% sure but give it a try

Issue in using recurrence in SSRS / Dynamic Reports on Sharepoint lists

I am using Reporting Service with SharePoint List
I am querying a calendar list, i have issue fetching recurring items. When i try to use expand recurrence i get the following issue
The query for recurrence i have is:
<RSSharePointList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ListName>SomeList</ListName>
<Query>
<Where>
<DateRangesOverlap>
<FieldRef Name='EventDate' />
<FieldRef Name='EndDate' />
<FieldRef Name='RecurrenceID' />
<Value Type='DateTime'><Today/></Value>
</DateRangesOverlap>
</Where>
</Query>
<QueryOptions>
<ExpandRecurrence>TRUE</ExpandRecurrence>
<CalendarDate><Today/></CalendarDate>
<ViewAttributes Scope='RecursiveAll' />
</QueryOptions>
<ViewFields>
<FieldRef Name="EventDate" />
<FieldRef Name="EndDate" />
<FieldRef Name="fRecurrence" />
<FieldRef Name="Hosted_x0020_By" />
<FieldRef Name="External_x0020_Attendees" />
<FieldRef Name="Catering_x0020_Requirements" />
<FieldRef Name="Company" />
<FieldRef Name="Recurrence_x0020_ID" />
<FieldRef Name="Room" />
<FieldRef Name="RecurrenceData" />
</ViewFields>
</RSSharePointList>
is it proper? is there any other way to handle recurrence with Reporting Service? Kindly help.
Formed each XML tag by creating a new Parameter of the type XML.