I have an SSRS report that uses the SharePoint List data connection. It works just fine using the query below. I want a Data Driven Subscription to email the report to the user whose email address shows in the report. The problem is that a user can show up multiple times in the same run of the report and SSRS seems to want to send them an email for each time their email address shows up. I used to do this all the time with reports that used standard t-SQL using Select Distinct but this xml based query language doesnt seem to have such a function.
Does anyone have any ideas about how to either get SSRS to be smart enough to send only one email per person OR get a variation on this query to only return each email address once?
Thanks
<RSSharePointList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ListName>SSRS_Subscriptions</ListName>
<ViewFields>
<FieldRef Name="Title" />
<FieldRef Name="count" />
<FieldRef Name="eMail" />
<FieldRef Name="Org" />
</ViewFields>
<Query>
<Where>
<Gt>
<FieldRef Name="count" />
<Value Type="Number">0</Value>
</Gt>
</Where>
</Query>
</RSSharePointList>
I am trying to search for files/folders whose names start with the entered text say 'foo'. I am able to retrieve files but the subfolders are not returned. Can anyone help. This is the CAML I am currently using:
<View Scope='Recursive'>
<Query>
<Where>
<BeginsWith>
<FieldRef Name='FileLeafRef' />
<Value Type='Text'>foo</Value>
</BeginsWith>
</Where>
</Query>
</View>
Try changing the scope to scope="RecursiveAll", this gets all files and all folders under the specified location. Also you should change:
<Value Type='Text'>foo</Value>
To
<Value Type='File'>foo</Value>
Also worth knowing is that FileLeafRef is the FILENAME (.docx etc) not the Title in SharePoint. Maybe you knew that :)
I am writing an internal API for my company which allows users to pass in SharePoint CAML query.
In side my function I take to user's query, and add some additional elements to it and then use the final query to retrieve required data from SharePoint.
Example:
User passes in:
<Query>
<Where>
<Eq>
<FieldRef Name='Category' />
<Value Type='Choice'>Bug</Value>
</Eq>
</Where>
</Query>
Internally, I modify the query to be:
<Query>
<Where>
<And>
<Eq>
<FieldRef Name='Category' />
<Value Type='Choice'>Bug</Value>
</Eq>
<Eq>
<FieldRef Name='AssignedTo' />
<Value Type='Integer'><UserID /></Value>
</Eq>
</And>
</Where>
</Query>
What do you think is the best way to validate queries sent by users?
If the queries that you're going to allow are fairly restricted, it might be a good approach to build a schema to represent what a valid query would be. Then you could just see if their xml is valid according to that schema. Also, I know that you can use the CAML Builder dll from code. I can't find an example of this right away, but there may be a way to use it's CAML building methods in a try/catch block to stop invalid queries from ever getting built.
Also, it occurs to me that you may need to watch out for the fact that the CAML query's FieldRef will need to be built using the internal name of the field which may differ from the display name.
I'd like to have a CAML query to get the events from a calendar list.
I want to get all the events including Today in the upcoming 30 or so days.
So far I have:
<Where>
<DateRangesOverlap>
<Geq>
<FieldRef Name=\"EventDate\" />
<Value Type=\"DateTime\">
<Today />
</Value>
</Geq>
<FieldRef Name=\"EndDate\" />
<FieldRef Name=\"RecurrenceID\" />
<Value Type=\"DateTime\">
<Month />
</Value>
</DateRangesOverlap>
</Where>
This does not work :( Any ideas?
As Nat has said you hint (but don't specify) that you are using recurring events in your calendar list so I am assuming that is the part that's not working?
You need to set the SPQuery.ExpandRecurrances and SPQuery.CalendarDate property prior to running the CAML query and you can only do this using the object model, not the web services or by setting an attribute in CAML.
Further - IIRC this will only expand out instances of recurring events that occur in the same calendar month as .CalendarDate so you have to run it multiple times to get a multi-month view.
This is by far the best reference covering recurring events I have found.
Understanding the SharePoint Calendar and how to export it to iCal format
Welcome to the nightmare of recurring events in SharePoint!
The recurrence does not actually add all the events into the list, but the CAML can only query from "actual" events stored in the list.
I'm using caml query to select all documents which were modified or added by user. Query runs recursively on all subsites of specified site collection.
Now problem is I can't get rid of folders which are also part of result set. For now I'm filtering them from result datatable. But I'm wondering: Is it possible to filter out folders from result set just by using caml?
This CAML actually does the trick:
<Where>
<Eq>
<FieldRef Name='FSObjType' />
<Value Type='Integer'>0</Value>
</Eq>
</Where>
that will not give you any folders.
So, i figured it out :)
You can use FieldRef='ContentType' in your caml query and specify typr of content type which you want to select or exclude from select.
So in my case I've added this condition to my caml expression:
<Neq><FieldRef Name='ContentType' /><Value Type='Text'>Folder</Value></Neq>
NOTE:
There are problems in multi language setup. Name of content type can be different, so it is good to get names of content types from resources
UPDATE:
It looks like I was too quick in my assumptions. I need to filter out all contett types based on folder content type, because in our projects such content types are used :(
I was not able to create workable query in caml, so I added view field element to my query which selects ContentTypeId of list item and I filter-out rows which are based on folder content type.
Code to do this is trivial, but it bothers me that such simple task cannot be done by pure caml.
If you're working with folders and you're using an SPQuery object you also may want to use the ViewAttributes field to allow for recursive item retrieval. Setting the value to Scope="Recursive" will retrieve items from subfolders and will not retrieve the folder objects in the result set.
myQuery.ViewAttributes = "Scope=\"Recursive\"";
According to the output from CAML Designer (created by Karine Bosch and Andy Van Steenbergen and distributed by the Belux Information Worker User Group) the correct CAML syntax is:
<Where>
<Eq>
<FieldRef Name='FSObjType' />
<Value Type='Integer'>0</Value>
</Eq>
</Where>
<QueryOptions>
<ViewAttributes Scope='RecursiveAll' />
</QueryOptions>
I tested this in PowerShell and got the expected result:
$qry = new-object Microsoft.SharePoint.SPQuery
$qry.Query = "<Where><Eq><FieldRef Name='FSObjType' /><Value Type='Integer'>0</Value></Eq></Where><QueryOptions><ViewAttributes Scope='RecursiveAll' /></QueryOptions>"
$items = $lib.GetItems($qry)
$items.Count
You can replace the <QueryOptions> tag in the CAML with the SPQuery object property ViewAttributes if you prefer, ie $qry.ViewAttributes = “Scope=’RecursiveAll’".
When testing this be sure to re-instantiate the SPQuery object each time as you cannot simple reassign the Query property. Once the query has been executed, any new value assigned to the Query property is ignored. So execute the entire PowerShell fragment.
Dave T.'s answer didn't work for me but taking it as an inspiration here's what I came up with:
<Where>
<BeginsWith><FieldRef Name="ContentTypeId" />
<Value Type="ContentTypeId">0x0101</Value>
</BeginsWith>
</Where>
The main problem is that we can only know ContentTypeId on a site level, because when a content type gets added to a list/library it becomes a list content type and its ID is appended with another GUID (0x010100...). And there's no NotBeginsWith condition in CAML, so we can not filter out folders, but we can include documents only which site content type id is 0x0101.
The solutions with FSObjType field don't work for me because I have libraries with far more files than a threshold so all the fields in the query must be indexed and I haven't found a way to index this field.
This is what worked for me
<Where>
<Eq>
<FieldRef Name='FSObjType' />
<Value Type='Number'>1</Value>
</Eq>
</Where>
Check my other answer CAML query that includes folders in result set
Simply changing the operators might get you what you need
<Where>
<NotIncludes>
<FieldRef Name='ContentTypeId' />
<Value Type='ContentTypeId'>0x0120</Value>
</NotIncludes>
</Where>
I'm not sure if that'll work.
For me also it worked as written below:-
<Where><Eq><FieldRef Name='FSObjType' /><Value Type='Integer'>1</Value></Eq></Where>