CAML query in getLIstItems method returns no rows of items - web-services

I am invoking Sharepoint's List Web services and using the getListItems() method. In particular, I am keen on specifying a CAML query because I really want it to just retrieve one item that I am specifically interested in. This I am doing by specifying a query in my XML string, in varying degrees of combinations, either by specifying the EncodedAbsUrl, the LinkFileName, the URL or the FileRef, with most results returning 0.
The XML query looks like this :
<?xml version="1.0" ?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> <S:Body><GetListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/"><listName>{5cbc4407-3851-4e00-964a-bb7e9b430f9f}</listName> <viewName></viewName> <rowLimit>1000</rowLimit> <webID></webID>
**<query><Query><Where><Eq><FieldRef Name = "FileRef"/><Value Type = "Text">"/Shared%20Documents/Ashish/Word_feb27.doc"</Value></Eq></Where></Query></query>**
<viewFields><ViewFields><FieldRef Name="FSObjType"/><FieldRef Name="LinkFilename"/><FieldRef Name="UniqueId"/><FieldRef Name="FileRef"/><FieldRef Name="FileRef"/><FieldRef Name="EncodedAbsUrl"/><FieldRef Name="FileSizeDisplay"/><FieldRef Name="_UIVersionString"/><FieldRef Name="_owshiddenversion"/></ViewFields></viewFields></GetListItems> </S:Body></S:Envelope>
Without the tags this Soap request does infact work, and it retrieves all the items that area available in the List. The frustration begins when i specify the query tag. In particular the Following combinations have been attempted by me
FieldRef.name = {LinkFileName, EncodedAbsUrl, URL,FileRef} and Value.type = {Text, URL}
Either they yield results with no 0 fields in it or they return internal errors. I figure, this is a syntactical issue and would rather shoot this question to you guys who have probably dunnit in the past to see where I am possibly messing it up.
Thanks

I would recommend using CAML Query Builder and Fiddler. Query builder can connect SP using Web services and you can build the query with that. After you got your expected results, capture the Web service request with Fiddler and use it :)
BTW: Have you considered using Sharepoint Client Object model? You do not have to worry about SOAP messages.

Remove the <query><Query> tags.

Related

Django haystack with Solr - how to specify GET parameters?

I'm using django_haystack with Solr 4.9. I've amended the /select request handler so that all requests use dismax by default.
The problem is that sometimes I would like to query specific fields, but I can't find a way to get the SearchQuerySet api to get it to play nicely with dismax. So basically I want to send the following (or equivalent) request to Solr:q=hello&qf=content_auto
I've tried the following aproaches:
Standard Api
SearchQuerySet().filter(content_auto='hello')
# understandably results in the following being sent to solr:
q=content_auto:hello
AltParser
query = AltParser('dismax', 'hello', qf="content_auto")
sqs = SearchQuerySet().filter(content=query)
# Results in
q=(_query_:"{!dismax+qf%3Dcontent_auto}hello")
Raw
query = Raw('hello&qf=content_auto')
# results in
q=hello%26qf%3Dcontent_auto
The last approach was so close, but since it escaped the = and & it doesn't seem to process the query correctly.
What is the best approach to dealing with this? I have no need for non-dismax querying so it would be preferable to keep the /select request handler the same rather than having to wrap every query in a Raw or AltParser.
In short, the answer is that it can't be done without creating a custom backend and SearchQuerySet. In the end I had to just revert back to a standard configuration and specifying dismax with an AltParser, slightly annoying because it affects your spelling suggestions.

Ember dynamic query parameters

I have what I believe to be common but complicated problem to model. I've got a product configurator that has a series of buttons. Every time the user clicks on a button (corresponding to a change in the product configuration), the url will change, essentially creating a bookmarkable state to that configuration. The big caveat: I do not get to know what configuration options or values are until after app initialization.
I'm modeling this using EmberCLI. After much research, I don't think it's a wise idea to try to fold these directly into the path component, and I'm looking into using the new Ember query string additions. That should work for allowing bookmarkability, but I still have the problem of not knowing what those query parameters are until after initialization.
What I need is a way to allow my Ember app to query the server initially for a list of parameters it should accept. On the link above, the documentation uses the parameter 'filteredArticles' for a computed property. Within the associated function, they've hard-coded the value that the computed property should filter by. Is it a good idea to try to extend this somehow to be generalizable, with arguments? Can I even add query parameters on the fly? I was hoping for an assessment of the validity of this approach before I get stuck down the rabbit hole with it.
I dealt with a similar issue when generating a preview popup of a user's changes. The previewed model had a dynamic set of properties that could not be predetermined. The solution I came up with was to base64 encode a set of data and use that as the query param.
Your url would have something like this ?filter=ICLkvaDlpb0iLAogICJtc2dfa3
The query param is bound to a 2-way computed that takes in a base64 string and outputs a json obj,
JSON.parse(atob(serializedPreview));
as well as doing the reverse: take in a json obj and output a base64 string.
serializedPreview = btoa(JSON.stringify(filterParams));
You'll need some logic to prevent empty json objects from being serialized. In that case, you should just set the query param as null, and remove it from your url.
Using this pattern, you can store just about anything you want in your query params and still have the url as shareable. However, the downside is that your url's query params are obfuscated from your users, but I imagine that most users don't really read/edit query params by hand.

How to use xQuery

I have an xsl file which I am currently grabbing all of the records from at once, starting them off as hidden and showing them as the user selects an id (<xsl:for-each select"">). The id value is currently being stored as a javascript variable selected by a user clicking that id.
I would like to use xQuery to grab the records, but only the records which match the ID the user has selected. Furthermore I generally understand the logic behind the rules in xQuery i just don't understand how to actually use it in my xsl file. Is it possible to use xQuery to maybe compare the value of the id(a js variable) to something using xQuery to grab only the records with that matching id?
Thank you for your time,
XQuery is a separate language from XSLT, not one that's embedded within XSLT. So depending on how you are launching XSLT, you can look for a parallel method for launching XQuery. For example, you may try XQIB (I have not tried it, but it looks promising).
If you need more help on that, let us know how you are running an XSLT processor, and what your data source is.
HOWEVER... It's not at all clear that XQuery is really what you want. It doesn't sound like you're wanting XQuery for something that you couldn't already do in XSLT. I'm not even sure you're not thinking of jQuery... which is a completely different animal.
It would be helpful if you could tell us more about where the records are coming from; what form they're stored in (an XML DOM?); and what you need to do with them. Probably the best solution then is that we show you how to do what you're trying to do within XSLT (or in Javascript).
Update
Looking at your new comment, I realize that I may have misunderstood where you are trying to run XQuery. You mentioned javascript above, from which I assumed you wanted to run XQuery in the browser, but now I think I jumped to the wrong conclusion - you are actually wanting to run it on the server maybe?
Regardless of where you're running it, either XSLT or XQuery can select "only the records which match the ID the user has selected". But if the XSLT/XQuery is running on the server, in order for this to work, you have to have either a page refresh or an AJAX call after the user selects an ID, to let the program on the server know what the selected ID is. I'm not sure if you already have that architecture set up, or if you're still trying to figure out how to use an AJAX call to retrieve data based on user input.
It sounds like you want to never send the whole set of records from server to client, not even initially (correct?). In that case, how does the user know what the set of available IDs is?
Anyway, you question may boil down to "How do you run XQuery from ASP.NET?" I have not tried to do that, but this article may help: Using Saxon.NET in ASP.NET; or this one: Querying XML Data with XQuery.
But again, I think XQuery may not be what you want. XQuery is not a querying language used within XSLT - that's more like XPath. XQuery is something you would use instead of XSLT, or beside it. So if you're using XSLT and you want to filter records according to what ID the user has selected, assuming you already know what ID the user has selected, the easy way to do that is within XSLT/XPath, rather than firing up a separate processor. E.g. you could say
<xsl:for-each select="//record[#ID = $usersChosenID]"> ...
Let me know if this is getting close to a solution for you. There are a variety of directions to expand this explanation, but I don't want to spend time scratching where there's no itch.

SharePoint Web Services - Updating ContentType field Required property?

I've been trying to programmatically reproduce the behavior of editing a Content Type's field properties in the SharePoint site management screen and selecting the "Required" radio button with no sucess using the WSS 3.0 web service's Webs.asmx "UpdateContentType" method.
The first difficulty was the issue with the MSDN documentation that said fields should be of a FieldRef type when in fact they need to be of a Field type (reference). Adding fields and deleting fields works fine after the fix, but updating fields seems to not function at all. (It should also be noted that I followed the recommendation on the previous link to use Method="2" for updating fields but it changes nothing, and using Method values other than 1 for adding or other than 3 for deleting also function correctly).
Here's the web service call (slightly modified with strings instead of XmlNode objects for readability):
SharePointWebServices.Webs webService = new SharePointWebServices.Webs();
webService.Url = "http://mysharepointserver/site";
webService.UseDefaultCredentials = true;
webService.UpdateContentType(
#"0x01005A089D9EC8A382458FB1F6C72096D52A",
#"<ContentType />",
#"<Fields />",
#"<Fields><Method ID=""1""><Field Name=""SomeField"" ID=""{8a4803c4-6545-4a7a-804d-237eebff0ce3}"" Required=""TRUE"" Hidden=""FALSE"" ReadOnly=""FALSE"" PITarget="""" PIAttribute="""" PrimaryPIAttribute="""" Aggregation="""" Node="""" /></Method></Fields>",
#"<Fields />");
After the call, the field is still Required="FALSE".
A quick look into the stssoap.dll assembly indicates that the "Required" property is apparently ignored during the update process. Is this normal behavior? If so, what is the recommended method for programmatically changing the "Required" field from client code (not executing on the SharePoint server)?
Any help would be greatly appreciated.
I've investigated this and found the same thing. I also tried adding the attribute Cmd="Update" to the Method element without success. This example of how to use UpdateContentType was helpful too.
I don't believe you will be able to do this with the out-of-the-box SharePoint services. You've verified from looking at stssoap.dll that this doesn't appear to work correctly. Another 'client'-style option is to use RPC methods but none appear to provide functionality for content types at all.
The web services are particularly frustrating because this type of not-so-edge case regularly comes up. It is very rare that I consider using them because of the time wasting involved with their limitations.
Do you have any option of deploying custom code to the server? You could develop this functionality using the object model and wrap it in your own custom web service (there is a walkthrough here) quite easily.
Here is an example adapted from Gabe Wishnie that does what you require:
SPContentType myContentType = myWeb.ContentTypes["myContentType"];
string internalName = myContentType.Fields["fieldToUpdate"].InternalName;
myContentType.FieldLinks[internalName].Required = false;
myContentType.Update(true);
Sorry this isn't more helpful but it's a common story when using the WSS 3.0 / SharePoint 2007 web services.

How can I iterate recursively though a sharepoint list using webservices?

in sharepoint webservices, I can use getListItems() to obtain the child elements of a list.
In a document library, sometimes the element is a folder.
"ows_FSObjType = 1"
Is there any way to ask SP for the child elements of this folder?
Querying with getListItems() using the folder ID gives me a SOAP Exception.
Edit:
I found that this webservice has got more method
Site Data Webservice
There is an "enumerate folder" method, which has got a "isFolder" property, but no method to recurse its contents.
Thank you, Sam. :)
On the GetListItems method, one of the optional parameters is an XMLNode called "QueryOptions". One of the elements you can put in that node is <Folder>.
So you should be able to pass in something like:
<QueryOptions>
<Folder>/My/Path/Here</Folder>
</QueryOptions>
I may be off a bit syntatically (didn't try to build and run a query when making this post), but the general idea should be sound. You can see more details on this in the MSDN GetListItems Reference.