Content Query Web Part - How do you OrderBy when you QueryOverride? - sharepoint

How do you order items when you override the QueryOverride property of the Content Query Web Part?
I have been given responsibility for a Web Part which extends the Content Query Web Part. The QueryOverride property of this Web Part is programmatically changed. Currently, the Web Part does not function as designed, as it does not order the items according to the appropriate field.
If I add an <OrderBy> node to the QueryOverride property I get an error message along the lines of 'something wrong with the query this web part is...' and the Content Query Web Part doesn't seem to have an OrderBy property which I could use instead.
The "QueryOverride property" part of this msdn article seems to suggest I should be able to add an <OrderBy> node to the QueryOverride but a number of web sites I've been reading suggest that this is not true.
So, how do you order items when you override the QueryOverride property of the Content Query Web Part?

Does your QueryOverride statement contain any Whitespace/linebreaks by any chance? I think I recall a while back having a situation where the QueryOverride needed to be all contained on one line, with no spaces between xml tags.
Weird I know, but try it out.
Also, for reference see the first community comment on the MSDN page http://msdn.microsoft.com/en-us/library/aa981241.aspx

THanks for this. Just to clarify, there should be no white spaces before or after the tags as well.
This did not work:
<![CDATA[
<OrderBy><FieldRef Name="EndDate" Ascending="False"/></OrderBy>
<Where>
But this did:
<![CDATA[<OrderBy><FieldRef Name="EndDate" Ascending="False"/></OrderBy><Where>
Wierd but thanks again for posting this answer, it saved me a lot of time.

Related

Customize search results and facets in Liferay 7.1

this is my first question, thanks in advance.
I am trying to customize the liferay results portlet and facets, with custom results. I need to filter the results once the search is launched, and remove the results that do not have layoutId :
with->
layoutIds = journalContentSearchLocalService.getLayoutIds(groupId,false,articleIdResult);
I´m doing this in a jsp fragment, but i think that it´s not correct.
I have been searching and i think the correct way is to modify the java class with the action, for example with acction coomand hook, is this correct?
Please, can you explain me the correct way to modify this functionalities?
Regards!!
ok. it looks you want result of journalarticle having display page is set. in that case, you need to look for JournalarticleModelPreFiltercontributor component extension or journalarticlepostprocessor if you are using legacy search api. when article gets indexed layoutuuid field is also indexed for each article. that field will have value if display page is set for specific web content or article.
So, you can use any of the above mentioned way to add check that this field should not be empty as search term. which will filter your result in request itself. instead adding overhead on result as later filtering in jsp.

CAML Query with Contains and Or Clause Issue

What I want to achieve : Take a keyword array as input and query Sharepoint List to return all rows which contain the keywords in the list.
I have built a simple CAML query to query my list with one keyword (pdf) .
<Query><Where><Contains><FieldRef Name='Keyword'/><Value Type='Text'>pdf</Value></Contains></Where></Query>
This works fine.
But, when I try to use Or clause in the CAML query(see below), I get the following error
"One or more field types are not installed properly. Go to the list settings page to delete these fields."
<Query><Where><Or><Contains><FieldRef Name='Keyword'/><Value Type='Text'>pdf</Value></Contains></Or></Where></Query>
I googled for the syntax and everything looks good. Please let me know what is missing.
Thanks in advance.
In CAML Query if you want to use OR you must and should have 2 conditions.
The field reference name must be the internal name. You can find this by going to the colmn page in list/library settings and the name is the end of the URL. Spaces and underscores in the name must be handled differently.

How do I get the guids of taxonomy/metadata terms for updating lists?

I'm integrating a legacy system with SP2010 using a literal SOAP calls. I can do a call such as CopyIntoItems or UpdateListItems and doing so, set metadata fields by providing a Fields node such as:
<Fields>
<FieldInformation Type="Note" DisplayName="Country_0"
Id="de1e6424-7a8a-42a5-8d21-73402fe2e609"
Value="UK|91c89925-16e6-4d41-9e71-ec45e8f2a113" />
...
</Fields>
In the Value attribute, I have to give the guid of the taxonomy or metadata term. That works fine in the above example since I happen to know the guid of the term UK. However, how can I dynamically figure out what the guid of some other value, say France for example, would be? I was thinking of making a utility to get them all and cache them on my system somehow so I can look them up easily, but where are they defined?
Possibly a stupid question, I get the feeling I've missed something...
The GetList call should allow you to get all the ID's.
But the UpdateListItems (and) call should work using just the internal names.
From the MSDN Sharepoint 2010 forum:
http://social.msdn.microsoft.com/Forums/eu/sharepoint2010general/thread/63553372-b87f-4d69-8d4c-63fb8a7b3c6d
Not sure if this is the best way but it's the answer I'm going with for the time being.

Query and/or Search for SharePoint Document ID

We have the sharepoint 2010 environment with Document ID's enabled.
Given (part of) a Doc ID, we want to programmatically retrieve the document(s) matching that ID. The problem seems to be that this column is rather special, in that it might need special handling.
Using an SPSiteDataQuery, fetching the _dlc_DocId field as part of the viewfields works fine. However, including it as part of the where query never results in any documents being fetched.
Using the Search API has gotten us nowhere at all.
Has anyone pulled this off, or any suggestions on how to tackle this problem?
[Update] Turns out we were fooled by subtle errors in the XML and bad debugging misinterpretations. This stuff just works fine.
I don't normally contribute to these sorts of things because cleverer people than I always get there before me, but as this is an old one with no proper answer I think I'll add my thoughts for those who find this page.
I was struggling with this but after a little digging around and learning a bit of Caml I got this working.
I am using the SharePoint Client Object Model against SharePoint 2010 and Office365 beta.
Start off your query by looking at the all list items query:
Microsoft.SharePoint.Client.CamlQuery.CreateAllItemsQuery().ViewXml
"<View Scope=\"RecursiveAll\">\r\n <Query>\r\n </Query>\r\n</View>"
Stick a where child inside the query
Then add in
<Eq><FieldRef Name="_dlc_DocId" /><Value Type="Text">MDXC2KE55ASN-3-80</Value></Eq>
replacing MDXC2KE55ASN-3-80 with the doc ID you are looking for inside the where.
Also don't forget you might want to make use of these too:
<ViewFields><FieldRef Name="_dlc_DocId" /></ViewFields>
<RowLimit>1</RowLimit>
Then use List.GetItems() method to bring back the ListItemCollection.
Just in case nobody comes with a slick solutions from the depths of the Sharepoint infrastructure:
What would Google Do?
Slice is, Dice it and dump it in a reverse index.
Solr and Lucene offer supreme tools for this. The idea is to cut the DocId's in small pieces and add the location of the document to the bucket for that piece.
Say We have "A real nice document" with Id ABCD123. You would add it to the buckets
ABCD, BCD1, CD12, D123
When searching for a partial ID (+ other data like dates, types, ...) you (well the search engine) creates the union of the buckets + applies additonal constraints.
To make this happen you need to write a spider for the sharepoint server and a routine which makes a record of data elements to be indexed.
Put a nice REST interface in frnt of it (actually SOLR already has that), integrate it in the main sharepoint server, and nobody needs to know there is something else running behind it.
These products can also incrementally update the indexes, so they can be kept up to date.
you could use the following to get the Document ID.
SPFile file = MethodToUploadFileToServer(web, filepath);
SPListItem item = file.Item;
string DocID = item.Properties["_dlc_DocId"].ToString();

How do you insert a query value as a parameter in sharepoint designer?

I am trying to create a Data Source in SharePoint Designer that connects to a SharePoint List via XML Web Services. I have created the Data Source and connected to the list in question. I can view all the data using GetListItems, and I want to filter it using the query parameter.
The query parameter takes an XmlNode, and when I put this as the value I get an error:
<Query>
<Where>
<Eq>
<FieldRef Name="Title" />
<Value Type="Text">Foo</Value>
</Eq>
</Where>
</Query>
Of course, I have not entered any tabs or newlines, as I only have a one-line entry field in SharePoint Designer. I receive an error with this query:
The server returned a non-specific
error when trying to get data from the
data source. Check the format and
content of your query and try again.
If the problem persists, contact the
server administrator.
I simply want to filter the list items resultset to be those with the Title field of "Foo". Can this be done in SharePoint Designer?
Update: escaping the < and > in this manner also fails:
<Query><Where><Eq><FieldRef Name="Title" /><Value Type="Text">Foo</Value></Eq></Where></Query>
Update: This appears to be a known issue with SoapDataSource components and SOAP calls. Apparently, they are over-encoding the <'s and >'s before they get submitted. The workaround given is to save the data source without a query parameter, and then to add it to the page and create a filter in the Common Data View Tasks dialog. I was able to get this to work using the following filter string:
[#ows_Title = 'Foo']
Unfortunately, this doesn't help me much as I am adding a Data View (showing the data) rather than a DataSource that I can use to point other controls to (like a drop-down list).
I'm still looking for a good solution on this that lets me place a datasource using SharePoint Designer.
There is a bug in SharePoint Designer. You cannot pass a Query object to a SOAPDataSource like this - the XML gets overencoded. Nothing you can do to fix it, except use Visual Studio.
I'll let you know if there's ever a hotfix available.
If anyone wants to quote this answer in a new answer, I'll accept that answer.
Did you XML encode the query? I believe you need to encode characters like <, > and " such that it is valid XML, e.g. :
<Query><Where>
and
<FieldRef Name="Title" />
This shows how variables can be used to address a similar issue.
Having worked with the list Title field, it does not return values for me unless I used "Contains".
This may not fix your error however.

Resources