isnull and in statement in CAML - sharepoint-2010

Is it possible to combine the sharepoint <In> statement with the <IsNull> statement? I only managed to get it working using an <Or> but would be great if you could place the <isNull> inside the <In> directly.
Thanks

The solution is as follows:
<Query>
<Where>
<In>
<FieldRef Name='MyLookupField' LookupId='TRUE'/>
<Values>
<Value Type='Lookup'></Value>
<Value Type='Lookup'>1</Value>
</Values>
</In>
</Where>
</Query>

Related

CAML Query with Nested OR's and AND's using SPServices

I have used this post a reference CAML query with nested AND's and OR's for multiple fields. The difference for mine is I do not need AND's with nested OR's inside of them.
I have the nested OR's working by themselves, however I need to add in three AND conditions. I'm not quite sure how to do this with the nested OR's .
My goal is as follows with a sample code included below. Test-1 is equal to A or B or C and Test-2 is equal to D and Test-3 is equal to E and Test-4 is equal to F.
<Where>
<And>
<Or>
<Eq>
<FieldRef Name='Test-1' />
<Value Type='Text'>A</Value>
</Eq>
<Or>
<Eq>
<FieldRef Name='Test-1' />
<Value Type='Text'>B</Value>
</Eq>
<Eq>
<FieldRef Name='Test-1' />
<Value Type='Text'>C</Value>
</Eq>
</Or>
</Or>
<And>
<Eq>
<FieldRef Name='Test-2' />
<Value Type='Text'>D</Value>
</Eq>
<Eq>
<FieldRef Name='Test-3' />
<Value Type='Text'>E</Value>
</Eq>
<Eq>
<FieldRef Name='Test-4' />
<Value Type='Text'>F</Value>
</Eq>
</And>
</And>
</Where>
Thanks for the help
Using U2U instead of another piece of software I was able to solve my problem by removing and moving the AND.

SharePoint CAML Query AND/OR operators

I would appreciate any help on getting my CAML query to work.
I have the following list:
| ID | Department | Status |
I am trying to get the query to return list items where ID=1, Department=Audit, and Status= "Stopped" OR "In Progress".
Can anyone please help?
Regards,
Query:
<Query>
<Where>
<And>
<Eq>
<FieldRef Name='ID' />
<Value Type='Counter'>1</Value>
</Eq>
<And>
<Eq>
<FieldRef Name='Department' />
<Value Type='Choice'>Audit</Value>
</Eq>
<Or>
<Eq>
<FieldRef Name='Status' />
<Value Type='Choice'>In Progress</Value>
</Eq>
<Eq>
<FieldRef Name='Status' />
<Value Type='Choice'>Not Started</Value>
</Eq>
</Or>
</And>
</And>
</Where>
</Query>
Note: it is assumed that Department is a Choice field
I would recommend you to utilize the tool that will help you build your CAML Queries, for example U2U Caml Query Builder

One or more field types are not installed properly. Go to the list settings page to delete these fields SP2010

Trying to use a CAML query for the first time but getting this error. Heres my query:
"<Where>
<And>
<And>
<And>
<And>
<Eq>
<FieldRef Name='Groupx0020Name'/>
<Value Type='Text'>" + groupName + "</Value>
</Eq>
<Eq>
<FieldRef Name='Arrived'/>
<Value Type='Boolean'>False</Value>
</Eq>
</And>
<Eq>
<FieldRef Name='Plant'/>
<Value Type='Text'>" + Plant + "</Value>
</Eq>
</And>
<Eq>
<FieldRef Name='Arrivalx0020date'/>
<Value Type='Text'>" + arrivalDate + "</Value>
</Eq>
</And>
<Eq>
<FieldRef Name='Left site'/>
<Value Type='Boolean'>False</Value>" +
</Eq>
</And>
</Where>";
I used a CAML designer to generate this query but still no luck any help will be greatly appreciated.
My problem was my content for the Plant field I had it set to text but the correct syntax was 'choice' as it was a drop down list value. I hope this helps anyone else with the same problem

Converting SQL Query to XML Query for SharePoint List

I'm using SQL Reporting 3.0 and I'm trying to query a SharePoint list. Since the SharePoint list can only be in XML inside of SQL reporting, I'm trying to figure out to to convert my SQL query into an XML query. The area I'm stuck at is inside of WHERE. I'm having difficulty with IN(#). Is there a way to convert this into an XML query? Thank you for your help its greatly appreciated.
SQL Query
SELECT Hours, Date, Project, ID, Created_By,Month
FROM TimeTracking
WHERE Project IN(#Project) AND Month IN(#Month)
XML Query
<RSSharePointList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ListName>Time Tracking</ListName>
<ViewFields>
<FieldRef Name="Hours" />
<FieldRef Name="Date" />
<FieldRef Name="Project" />
<FieldRef Name="ID" />
<FieldRef Name="Created_By" />
<FieldRef Name="Month" />
</ViewFields>
<Query>
<Where>
?
</Where>
</Query>
</RSSharePointList>
Here's an example on MSDN on using FOR XML PATH to return your query as XML. You can also add a root element by using ROOT.
Please refer to te following article:
http://msdn.microsoft.com/en-us/library/bb510462.aspx

SOAP call with query on result (SSRS, Sharepoint)

I created a report in VS using a shared data source which is connected to a sharepoint list. In the report I created a dataset with a SOAP call to the data source so I get the result from the sharepoint list in a table.
this is the soap call
<Query>
<SoapAction>http://schemas.microsoft.com/sharepoint/soap/GetListItems</SoapAction>
<Method Namespace="http://schemas.microsoft.com/sharepoint/soap/" Name="GetListItems">
<Parameters>
<Parameter Name="listName">
<DefaultValue>{BD8D39B7-FA0B-491D-AC6F-EC9B0978E0CE}</DefaultValue>
</Parameter>
<Parameter Name="viewName">
<DefaultValue>{E2168426-804F-4836-9BE4-DC5F8D08A54F}</DefaultValue>
</Parameter>
<Parameter Name="rowLimit">
<DefaultValue>9999</DefaultValue>
</Parameter>
</Parameters>
</Method>
<ElementPath IgnoreNamespaces="True">*</ElementPath>
</Query>
THis works fine, I have a result which I can show in a report, but I want to have the ability to select a parameter to filter the result on. I have created a parameter and when I preview the Report I see the dropdownbox which I can use to make a selection from the Title field, when I do this it still shows the first record, obviously it doens't work yet (DUH!) because I need to create a query somewhere, But! I have no idea where, I tried to include
<Where>
<Eq>
<FieldRef Name="ows_Title" />
<Value Type="Text">testValue</Value>
</Eq>
</Where>
in the the soap request but it didn't worked... I've searched teh intarwebz but couldn't find any simliar problems... kinda stuck now...any thoughts on this?
EDIT
Here's the query I used according to the blogpost Alex Angas linked.
<Query>
<SoapAction>http://schemas.microsoft.com/sharepoint/soap/GetListItems</SoapAction>
<Method Namespace="http://schemas.microsoft.com/sharepoint/soap/" Name="GetListItems">
<queryOptions></queryOptions>
<query><Query>
<Where>
<Eq>
<FieldRef Name="ows_Title"/>
<Value Type="Text">someValue</Value>
</Eq>
</Where>
</Query></query>
<Parameters>
<Parameter Name="listName">
<DefaultValue>{BD8D39B7-FA0B-491D-AC6F-EC9B0978E0CE}</DefaultValue>
</Parameter>
<Parameter Name="viewName">
<DefaultValue>{E2168426-804F-4836-9BE4-DC5F8D08A54F}</DefaultValue>
</Parameter>
<Parameter Name="rowLimit">
<DefaultValue>9999</DefaultValue>
</Parameter>
</Parameters>
</Method>
<ElementPath IgnoreNamespaces="True">*</ElementPath>
</Query>
I tried to put the new query statement in every possible way in the existing, but it doesn't work at all, I do not get an error though so the code is valid, but I still get an unfiltered list as return... pulling my hair out here!
A post at:
http://social.msdn.microsoft.com/forums/en-US/sqlreportingservices/thread/1562bc7c-8348-441d-8b59-245d70c3d967/
Suggested using this syntax for placement of the <Query> node (this example is to retrieve the item with an ID of 1):
<Query>
<SoapAction>http://schemas.microsoft.com/sharepoint/soap/GetListItems</SoapAction>
<Method Namespace="http://schemas.microsoft.com/sharepoint/soap/" Name="GetListItems">
<Parameters>
<Parameter Name="listName">
<DefaultValue>{CE7A4C2E-D03A-4AF3-BCA3-BA2A0ADCADC7}</DefaultValue>
</Parameter>
<Parameter Name="query" Type="xml">
<DefaultValue>
<Query>
<Where>
<Eq>
<FieldRef Name="ID"/>
<Value Type="Integer">1</Value>
</Eq>
</Where>
</Query>
</DefaultValue>
</Parameter>
</Parameters>
</Method>
<ElementPath IgnoreNamespaces="True">*</ElementPath>
</Query>
However this would give me the following error:
Failed to execute web request for the specified URL
With the following in the details:
Element <Query> of parameter query is missing or invalid
From looking at the SOAP message with Microsoft Network Monitor, it looks as though the <Query> node is getting escaped to <Query> etc, which is why it fails.
However, I was able to get this to work using the method described in Martin Kurek's response at:
http://www.sharepointblogs.com/dwise/archive/2007/11/28/connecting-sql-reporting-services-to-a-sharepoint-list-redux.aspx
So, I used this as my query:
<Query>
<SoapAction>http://schemas.microsoft.com/sharepoint/soap/GetListItems</SoapAction>
<Method Namespace="http://schemas.microsoft.com/sharepoint/soap/" Name="GetListItems">
<Parameters>
<Parameter Name="listName">
<DefaultValue>{CE7A4C2E-D03A-4AF3-BCA3-BA2A0ADCADC7}</DefaultValue>
</Parameter>
<Parameter Name="query" Type="xml">
</Parameter>
</Parameters>
</Method>
<ElementPath IgnoreNamespaces="True">*</ElementPath>
</Query>
And then defined a parameter on the dataset named query, with the following value:
<Query><Where><Eq><FieldRef Name="ID"/><Value Type="Integer">1</Value></Eq></Where></Query>
I was also able to make my query dependent on a report parameter, by setting the query dataset parameter to the following expression:
="<Query><Where><Eq><FieldRef Name=""ID""/><Value Type=""Integer"">" &
Parameters!TaskID.Value &
"</Value></Eq></Where></Query>"
See the question and answers for GetListItems Webservice ignores my query filter. This shows you how (and how not to) set up your SOAP call to include a query. You probably need to wrap your query with another <Query></Query>.
You have your FieldRef as
ows_Title
I believe it should just be Title.
When you get results from the SOAP request all your field name will begin with
ows_
Brilliant, thanks. This solution worked for queryOptions also.
In the Query:
<Parameter Name="queryOptions" Type="xml">
</Parameter>
And in the parameters list of the dataset:
Name: queryOptions
Value: <QueryOptions><Folder>Shared Documents/MyFolder</Folder></QueryOptions>