Below you will find pages that utilize the taxonomy term “CAML”
Using CAML with SharePoint REST API
Do you prefer REST over CSOM as I do? I’ll skip the whys. Andrew Connell put it already in wrtiting so nicely. Well, if you do prefer REST, then you must have discovered some shortcomings of REST, or its incompleteness compared to CSOM. I think of:
- Inability to filter items based on multivalued taxonomy fields
- Inability to filter items based on user fields where user is added through a group, rather than directly, e.g. AssignedTo=[Me] combined with a SharePoint group.
- …
In such situations I was forced to use CSOM. Until yesterday. Yesterday I learned that we can actually use CAML queries in REST requests. This enables using REST in all situations. The REST API is still developed and many features are added. Maybe a particular operation that needs a CAML query today, can be supported in the core REST API and can be easily refactored then. But until then, we can use CAML queries in REST requests. Here are the important things about it:
Paging with JSOM
If there are many list items you try retrieve with javascript object model,paging could be very useful. Today I came across a wonderful blog post series about javascript object model in SharePoint: The SharePoint javascript object model - Resources and Real World Examples posted by David Mann and published on Aptilon Blog. There is an example how to achieve paging with JSOM. The key is items.get_listItemCollectionPosition() and query.set_listItemCollectionPosition() I have refactored David’s example to avoid global variables and to put into a module. Here is it. If you have a Tasks list in your site with many items, just hit F12 to open the console and paste this and see the result:
Ändra query på en SPView i koden
När man vill ändra hur data ska visas i en SPView i SPList, då måste man ändra CAML-Query. Det enklaste sättet att skapa en CAML Query är att använda ett program som heter CAML Query Builder. Ta bara bort och för att de behövs inte. Sedan är det bara att loopa igenom alla vyer man behöver.
private void UpdateQueryInGroupViews(SPList list)
{
for (int i = 1; i < 11; i++)
{
string viewname = String.Format("Group {0:D2}", i);
SPView view = list.Views\[viewname\];
string query =
String.Format(
"<Where><Or><Contains><FieldRef Name='Group' />"
+ "<Value Type='Text'>{0:D2}</Value></Contains>"
+ "<IsNull><FieldRef Name='Group' /></IsNull></Or></Where>"
+ "<OrderBy><FieldRef Name='EventDate' Ascending='True' />"
+ "</OrderBy>", i);
view.Query = query;
view.Update();
}
}
I denna query sorterar vi efter Start Date och visar bara händelser för sin grupp.