Can I use regex in SharePoint GetListItems web service - regex

I need to list all the files located in one document library that match a specific naming convention: The documents to retrieve are all in the form 'Report xxxx-xx-xx'.
I have to use the GetListItems web service.
Is there a way to collect all these documents in one call?
How to write the 'where' section in the query part?
Can I use some regex in this?
Thanks

Reading
http://msdn.microsoft.com/en-us/library/ms471093(v=office.12).aspx
http://msdn.microsoft.com/en-us/library/ms414805(v=office.12).aspx
the construction of a WHERE clause seems clear:
<Query>
<Where>
<Geq>
<FieldRef Name="Expires"/>
<Value Type="DateTime">
<Today/>
</Value>
</Geq>
</Where>
<OrderBy>
<FieldRef Name="Modified"/>
</OrderBy>
</Query>
However there does not seem to be a way to use regexes. Perhaps the best you can do is to use the BeginsWith element on the "Report" and Contains element to search for a dash. There is a good example for this at
http://msdn.microsoft.com/en-us/library/ms196501(v=office.12).aspx

Perhaps you could add a Calculated Column on your document library, that performs a string manipulation and/or test operation on your title text, and returns eg something that can then easily be picked up in your where clause?
This might help limit the result set at the server side...
=IF(LEFT([TitleColumn],7)="Report ", if(ISNUMBER(DATEVALUE(RIGHT([TitleColumn],10))), "TRUE", "FALSE"), "FALSE")
Refer to Microsoft's Calculated Field Formulas for what's available in calculated columns.

Related

Sitecore date comparison doesn't return expected results

I'm trying to return a list of courses using an iqueryable query but am having issues with some date comparisons.
I'm currently using the code
query = query.Where(r => r.EndDate >= DateTime.UtcNow);
which returns courses with dates in the future, however it will not return courses that end on the same day with a time ending later than the time returned by DateTime.UtcNow.
Any ideas what I am doing wrong?
I've just used Luke to check the index and if I use
end_date:[20170531t092205609z TO *]
I get back the exact results I need, however in the logs the actual query uses
+end_date:[20170531t092205609z TO *] +_template:a84b75fccac64eafa746f4b71e628adc - Filter :
I then get more results back including the course I was missing.
a) Why do I get more results back using the second query?
b) Why is it that in my C# code the results returned do not match the search results?
Had a similar issue and described our solution here: https://ggullentops.blogspot.be/2015/12/sitecore-lucene-index-and-datetime.html.
Our problems had 2 reasons:
The first reason is that Sitecore stores its DateTimes in UTC (which was an hour difference with our local time)
Second reason was that Sitecore uses "t" in the dates as lowercase in the query. In my index however they are all uppercase. If I try the query with Luke it does give me the wrong results indeed.. When I alter the query in Luke to use uppercase T it works correctly..
The easiest solution we found was a format attribute in the index config:
<field fieldName="datefrom" storageType="YES" indexType="UNTOKENIZED" vectorType="NO" boost="1f"
format="yyyyMMdd" type="System.DateTime"
settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider"/>
(note the format="...")

Is there a way to escape and use ColdFusion query reserved words as column names in a query of query?

I'm working with a query that has a column named "Date."
The original query returns okay from the database. You can output the original query, paginate the original query, get a ValueList of the Date column, etc.
Query of Query
<cfquery name= "Query" dbtype= "query">
select
[Query].[Date]
from [Query]
</cfquery>
Response from ColdFusion
Query Of Queries syntax error. Encountered "Date. Incorrect Select
List,
Typically, I use descriptive names so I haven't run across this issue previously.
In this case, I'm working with a stored procedure that someone else wrote. I ended up modifying the stored procedure to use a more descriptive column name.
I have a service I use for transforming, searching and sorting queries with ColdFusion. I'm curious to know the answer to my original question, so that I can modify my service to either throw a better error or handle reserved words.
Is there a way to escape and use ColdFusion query reserved words as column names in a query of query?
The following code works fine for me:
<cfset query = queryNew("date")>
<cfdump var="#query#">
<cfquery name= "Query" dbtype= "query">
select
[Query].[Date]
from [Query]
</cfquery>
<cfdump var="#query#">
In standard mysql you'd "escape" the fields by using the ` character.
So for example:
select `query`.`date` from `query`
Try that and see if it works?

Searching Attachments in SharePoint 2010 Lists using CAML

I need help on searching attachments i.e Word Document, PDF etc which are attached to the list during inserting Item in SharePoint 2010 using CAML queries.
I tried with this query
<Query>
<Where>
<Eq>
<FieldRef Name="Attachments" />
<Value Type="Attachments">WordDocument1.docx</Value>
</Eq>
</Where>
</Query>
im not able to get any results if i give this query.
Please help.
The problem here is that the Attachments field of a SharePoint list does not store the attachments itself. This column only return whether a certain list item has an attachment or
not.
The attachments are not stored in a SharePoint list. Therefore I don't think it's possible to retrieve them with a CAML query.

Is there a way to only return documents from a SharePoint Web Service Search?

If a query the SharePoint Web Service Search, is there a way to send a parameter so that it only return documents?
There is of course the possibility to filter the result using the isDocument column, but is it possible during the query?
What do you mean by "during the query"? Providing a filter on the IsDocument column is applied query time! This is one way to return documents - another could be to create a search scope for documents only. But again, you will need to specify it in the query.
I guess you can use the beginsWith filhter in the query and query for all items that begins with a documente content type id:
<Where>
<BeginsWith>
<FieldRef Name='contentTypeId'/>
<Value Type='Text'>0x0101</Value>
</BeginsWith>
</Where>
see here for information about content type id and here is how you can use the query.

Sharepoint Lists - GroupBy?

I'm trying to get data from a Sharepoint list and put it into some Flex graphs. I can call the list data just fine using a CAML query, but I want to use a GroupBy to consolidate the rows by Teams. So, for example Team 1 may have 20 records, Team 2 may have 8 records, and Team 3 might have 25 records... Instead of showing 53 records, I want to show 3... just "Team 1, Team 2, Team 3" and the sum of the cost of each entry.
I see where CAML provides a GroupBy element, but I can't seem to get it to work. Also, I was only able to get the OrderBy element to work when I used the OrderField element instead of the FieldRef element like 90% of the books and websites recommend. If I do use FieldRef, OrderBy doesn't work anymore, which makes no sense to me. Something must be awry...
Here is my CAML Query as it stands...
---------------------------------------------------
<queryRequest xmlns="http://schemas.microsoft.com/sharepoint/dsp">
<dsQuery resultContent="dataOnly" resultRoot="Rows" resultRow="Row" columnMapping="attribute">
<ViewFields>
<FieldRef Name="Team"></FieldRef>
<FieldRef Name="Cost"></FieldRef>
<FieldRef Name="EANo"></FieldRef>
</ViewFields>
<Query>
<GroupBy collapse="true">
<FieldRef Name="Team"/>
</GroupBy>
<OrderBy>
<OrderField Name="Cost"/>
</OrderBy>
</Query>
</dsQuery>
</queryRequest>
---------------------------------------------------
This is with OrderBy working, but GroupBy not working. Help!
Thanks!
I ran the following query and seems to be working fine for me.
<Query>
<GroupBy collapse="true">
<FieldRef Name='Date' />
</GroupBy>
<OrderBy>
<FieldRef Name='Title' />
</OrderBy>
</Query>
I suggest you use the U2U CAML Query Builder tool to build and test your query's