Caml Query Sharepoint List



I'm attempting to pull a list from SharePoint via CAML and I want the list returned ordered by a specific field. The field is a lookup field. The query comes back unordered when I set the OrderBy to be the lookup field, if I use a text field it's fine. The U2U CAML query builder will return this query ordered when I build it in the editor. Filtering List Item using CAML query in sharepoint I want to filter list items on the basis of Current user sharepoint group, so only list items having value in column same as sharepoint group name can display.

This post is about directly applying aggregations on a SharePoint List, without specifying any grouping condition. If you want to group SharePoint List data before applying aggregation then, refer to this post, SharePoint Group By.

I must admit that this turned out to be little tricky than what I had imagined. The situation was fairly simple. I had a SharePoint List. I had applied couple of Totals functions, Standard Deviation & Variance, on one of its Number field in two separate custom views. I just wanted to retrieve those values from client side. That’s it! My initial assessment was there must be some function/property that I can easily query from the client. As it seemed initially, there’s no direct way of doing that. Fine, just another day at the office for a SharePoint developer 😉

What irked me was when I googled the issue, almost all the responses were like it’s not possible! The value is never stored. SharePoint calculates it on the fly, and then it displays the result on the View Page using its XSLT. The only possible solution was to retrieve all the items first from the SP, and then perform your calculation like, Sum, Avg, etc. on the client side. Though technically, the approach was correct but, somehow it didn’t appeal to me for the following reasons:

  • Doing the same calculation on the client-side which SP was already doing seemed pretty weird.
  • It could result in huge performance overhead considering your List has large number of items or it could grow exponentially in the foreseeable future. Downloading all the items in that case and then looping through all of them to calculate the Sum, Avg, etc., would only make things slower and slower.

I was somehow, still not convinced that it’s not possible. If SharePoint is calculating it, why should I have to re-calculate the same? Couldn’t I just get the value from the SharePoint itself? I then looked into the schema of one of the custom view.

Notice the little Aggregations tag. That was like, the first ray of hope. Aggregations seemed like the possible solution ’cause it was carrying the function definition, VAR, for VARIANCE.

Wrong Approach

So I ran the following code, with the Aggregations tag in the ViewXml, to get the Standard Deviation of the numeric field, OrderID:

I only received the first ListItem with its properties but no Standard Deviation! If I don’t mention the RowLimit then, all the ListItems were being retrieved. I was definitely taking the wrong approach ’cause I only needed the aggregate function result and not the entire set of ListItems.

Correct Approach

I knew, that the approach had to be altered. CAML query is the answer but you can’t get a single calculated result from GetItems. I then started looking at various other methods that the List offers and then, I came across the method, RenderListData. It returns a ClientResult (read JSON) and accepts viewXml (read CAML) as parameter. So I ran the following code:

And voila! It’s done! 😎
The output for both the queries were:

Look at the values, OrderID.VAR, OrderID.STDEV, & OrderDate.COUNT. The count field reveals that the List had 1599 items. Although, some fields of the first item were retrieved due to the RowLimit being set to 1, still the response, I would say, was crisp and to the point only instead of the entire ListItemCollection which seemed to be the only option earlier. The VAR (Variance) & STDEV (Standard Deviation) can be verified from the screen-shots below

Std Deviation

Variance

Caml query sharepoint list c#

Here’s the list of all the Totals function along with their TYPE values. To fetch the result of any of the Totals function just, use the corresponding Type value in the Aggregations property.

Si No.

Total Function

Function Type

1CountCOUNT
2AverageAVG
3MaximumMAX
4MinimumMIN
5SumSUM
6Std DeviationSTDEV
7VarianceVAR

Footnotes

Title: Hello World Music Download By: Lady Antebellum Format: Music Download Vendor: Daywind Music Group Publication Date: 2011 UPC: DIG21 Stock No: WWDL152139-CP. From the Album Need You Now 4.5 out of 5 stars 28 ratings. I love all of Lady Antebellum work, but I enjoyed the song above most. It has a very nice comfortable feel that is tangible. I know where to come to get great single mp3's. This one is a song I'll always treasure even if it's a sad one, it carries. Lady Antebellum was the name of the American country trio that changed its name to Lady A on 11 June 2020, amid the George Floyd protests. The trio originally formed in Nashville, Tennessee, in 2006 by Charles Kelley (lead and background vocals), Dave Haywood (background vocals, guitar, piano, mandolin) and Hillary Scott (lead and background. Lady antebellum hello world mp3 Traffic crawls, cell phone callsTalk radio screams at meThrough my tinted window I seeA little girl, rust red minivanShe's got chocolate on her faceGot littl. Download Hello world on Hungama Music app & get access to Lady Antebellum - Need You Now unlimited free songs, free movies, latest music videos, online radio, new TV shows and much more at Hungama. Listen to free mp3 songs, music and earn Hungama Coins, redeem Hungama coins for free subscription on Hungama Music App and many more free gifts.

  • Using CSOM, I have fetched these values in a C# console application. Though, I haven’t tried the JavaScript approach, I don’t see why the same won’t work there considering that the RenderListData method is available in both, REST API and sp.js.
  • All these calculations, in this blog, has been carried out on the “Sales Order Details” table of the AdventureWorks-2012 database.

We use a Sharepoint list to track various information. The toolsets that we create should ideally read from these lists, so that every team member shares the same information and can see real-time data. To do this, we used VBScript (we made a HTA actually…).

Caml Query Sharepoint List C#

It uses a SOAP request to ‘ask’ for information from Sharepoint. Part of this request uses a CAML query to specify exactly what we’re after.

Sharepoint List Caml Query Powershell

**UPDATE**

Mixcraft 9 free registration code. The example above pulls back ALL fields from the list. We may want to refine this to only pull back specific fields by adding the following to our SOAP request:

Caml Query Examples

The first viewFields tag above should be at the same level as the <query> tag in the example above. In other words, you can paste this code directly above the <query> line in the SOAP request.