CAML Query Builder
Akumina Foundation 3.4 and above
The CAML Query Builder is an addition to the Akumina Framework that provides an easy way of generating CAML Queries. This frees up the developer from having to write XML by hand, or Googling CAML syntax to get a valid CAML query.
The CAML Query Builder object only requires two inputs, an Akumina.CamlQueryCriteria object, which contains the properties that will be used in the query, and the rowLimit, which is simply the number of rows that will be returned from the list. A proper call to the CAML Query Builder will follow the format below
In our first example, we query on an item by AkId as well as which matches a title.
var q = new Akumina.CamlQueryCriteria();
q.ListName = "CompanyNews_AK";
q.SelectFields = ["Title","Summary"];
var exp = (new Akumina.PropertyExpression("Title").EqualTo("Featured In the News_Company Awards"));
var exp2 = new Akumina.PropertyExpression("AkId").EqualTo(1);
q.Filter = (exp.And(exp2));
q.Filter = exp;
var query = Akumina.CamlQueryBuilder.Build(q, 5);
This yields the query
<View><ViewFields><FieldRef Name="F1"/></ViewFields><Query><Where><Eq><FieldRef Name="Title"/><Value Type="Text">Featured In the News_Company Awards</Value></Eq></Where><OrderBy></OrderBy></Query><RowLimit>5</RowLimit></View>
Here we will insert a CAML query built buy the Akumina.CamlQueryBuilder into a SharePoint JSOM function accessing a list. The original example can be found at https://msdn.microsoft.com/en-us/library/office/hh185007(v=office.14).aspx
function retrieveListItems() {
var q = new Akumina.CamlQueryCriteria();
q.ListName = "CompanyNews_AK";
q.SelectFields = ["Title","Body", "ID"];
var exp = (new Akumina.PropertyExpression("Title").EqualTo("Featured In the News_Company Awards"));
var exp2 = new Akumina.PropertyExpression("AkId").EqualTo(1);
q.Filter = (exp.And(exp2));
q.Filter = exp;
var query = Akumina.CamlQueryBuilder.Build(q, 5);
var clientContext = new SP.ClientContext();
// set the listname
var oList = clientContext.get_web().get_lists().getByTitle(q.ListName);
var camlQuery = new SP.CamlQuery();
// Set the viewXML to the built CAML
camlQuery.set_viewXml(query);
this.collListItem = oList.getItems(camlQuery);
clientContext.load(collListItem);
clientContext.executeQueryAsync(
Function.createDelegate(this, this.onQuerySucceeded),
Function.createDelegate(this, this.onQueryFailed)
);
}
function onQuerySucceeded(sender, args) {
var data = {};
data.Items = [];
var listItemEnumerator = collListItem.getEnumerator();
while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
var listItemInfo =
{
"ID": oListItem.get_id(),
"Title": oListItem.get_item('Title'),
"Body": oListItem.get_item('Body')
};
data.Items.push(listItemInfo);
}
console.log(data);
}
function onQueryFailed(sender, args) {
console.log('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
The CAML Query Criteria object contains all properties needed for the CAML Query Builder to construct your query. These properties are explored below
The name of the list you are querying. This is passed as a string
var criteria = new Akumina.CamlQueryCriteria();
criteria.ListName = "Sample_AK";
The fields we are retrieving from the list. This is as a string array.
var criteria = new Akumina.CamlQueryCriteria()
criteria.SelectFields = ["ID", "Title", "AkNumber"];
The query filter expression. All values that you would expect to find between the <Where></Where>
tags within a query. The Filter is constructed through the use of the Akumina.PropertyExpression object
The Akumina.PropertyExpression object creates an expression based a column name within the list. Expressions can be generated through the following examples
var exp = new Akumina.PropertyExpression("Title").Contains("akumina");
This yields the Query Filter expression
<Where><Contains><FieldRef Name="Title"/><Value Type="Text">akumina</Value></Contains></Where>
var exp = new Akumina.PropertyExpression("Title").EqualTo("akumina");
This yields the Query Filter expression
<Where><Eq><FieldRef Name="Title"/><Value Type="Text">akumina</Value></Eq></Where>
var exp = new Akumina.PropertyExpression("AkId").NotEqualTo(1);
This yields the Query Filter expression
<Where><Neq><FieldRef Name="AkId"/><Value Type="Text">1</Value></Neq></Where>
var exp = new Akumina.PropertyExpression("AkId").GreaterThan(1);
This yields the Query Filter expression
<Where><Gt><FieldRef Name="AkId"/><Value Type="Text">1</Value></Gt></Where>
var exp = new Akumina.PropertyExpression("AkId").GreaterThanOrEqualTo(1);
This yields the Query Filter expression
<Where><Geq><FieldRef Name="AkId"/><Value Type="Text">1</Value></Geq></Where>
var exp = new Akumina.PropertyExpression("AkId").LessThan(1);
This yields the Query Filter expression
<Where><Lt><FieldRef Name="AkId"/><Value Type="Text">1</Value></Lt></Where>
var exp = new Akumina.PropertyExpression("AkId").LessThanOrEqualTo(1);
This yields the Query Filter expression
<Where><Leq><FieldRef Name="AkId"/><Value Type="Text">1</Value></Leq></Where>
exp = (new Akumina.PropertyExpression("Title").Contains("akumina"));
exp2 = new Akumina.PropertyExpression("AkId").EqualTo(12);
andExp = (exp.And(exp2));
This yields the Query Filter expression
<Where><And><Contains><FieldRef Name="Title"/><Value Type="Text">akumina</Value></Contains><Eq><FieldRef Name="AkId"/><Value Type="Text">12</Value></Eq></And></Where>
exp = (new Akumina.PropertyExpression("Title").Contains("akumina"));
exp2 = new Akumina.PropertyExpression("AkId").EqualTo(12);
orExp = (exp.Or(exp2));
This yields the Query Filter expression
<Where><Or><Contains><FieldRef Name="Title"/><Value Type="Text">akumina</Value></Contains><Eq><FieldRef Name="AkId"/><Value Type="Text">12</Value></Eq></Or></Where>
The order in which we want to retrieve rows based on their fields. This is passed as an array of Akumina.SortDirection objects.
var criteria = new Akumina.CamlQueryCriteria()
var orderby = [];
orderby.push(new Akumina.SortOrderAndDirection("Title", Akumina.SortDirection.Ascending));
orderby.push(new Akumina.SortOrderAndDirection("AkId", Akumina.SortDirection.Descending));
criteria.OrderBy = orderby;
The id of the content langugage to be retrieved from the list. This is a numeric value and can be retrieved from the UserContext.
var criteria = new Akumina.CamlQueryCriteria()
//language code (Croatian)
criteria.LanguageId = 1050;
var criteria = new Akumina.CamlQueryCriteria()
//language code from UserContext
criteria.LanguageId = Akumina.Digispace.UserContext.LanguageId;
- Building a Custom Widget: Overview
- Building A Custom Widget: Hello World Widget
- Building A Custom Widget that accesses SharePoint Lists
- Building A Generic List Control Widget
- Custom Widget: SP Sites List
- Building A Custom Widget: Angular Stock Ticker Widget
- Building A Custom Widget: Flickr Image Library
- Building A Custom Widget: Stock Ticker Widget
- Building A Custom Widget that Accesses a List
- Building A Custom Widget: Yammer Widget
- What's in the Core Site?
- Troubleshooting in the Core Site
- Building your first widget
- Building a Custom Masterpage
- Building a Page Layout
- Applying Custom Styles
- Widget Manager: Overview
- Widget Manager: Retrieving View Icons
- Widget Manager: Adding an Existing Widget to a Page
- Widget Manager: Creating a Custom View for an Existing Widget
- Building a Customdataload Callback: Accessing a List
- Building A Customdataload Callback: Accessing a List from a Different Site
- Building A Customdataload Callback: Hello World
- Building a Customdataload Callback: Overview
- Building A Customdataload Callback: Third Party Data
- Changing the Loading View of a Widget
- Multilingual widget instances
- Search: Displaying search results with the GenericSearchList widget
- Upgrading Widget Snippets: Overview
- Upgrading Widget Snippets: Updating a Custom Built Widget Snippet
- Upgrading Widget Snippets: Updating an OOB Widget Snippet
- View Creation: Handlebars
- View Manager: Creating a Custom View
- Widget Development Process: Widget Decision Tree
- Widget Development Process: Widget Design Use Cases
- Eventing: OOB Digital Workplace Events
- Eventing: Overview
- Framework Integration Points
- Framework: ConfigurationContext
- Framework: UserContext
- Generating a HAR file for troubleshooting performance
- Getting List Items with JSOM
- Masterpage: Enabling a Custom Masterpage to work with the Akumina Widget Framework
- Multilingual tokens
- Multilingual: Akumina Framework language awareness
- Page Life Cycle: Overview
- Page Life Cycle framework: execution steps
- Page Life Cycle: Accessing a List
- Page Life Cycle: Accessing a List (3.3.0.0)
- Page Life Cycle: Accessing UserContext
- Page Life Cycle: Accessing UserContext (3.3.0.0)
- Page Life Cycle: Adding Custom Steps
- Page Life Cycle: Adding Custom Steps (3.3.0.0)
- Page Life Cycle: Akumina Foundation Shipped Site Steps
- Page Life Cycle: Appending Additional Markup
- Page Life Cycle: Appending Additional Markup (3.3.0.0)
- Page Life Cycle: Core Steps
- Page Life Cycle: Hello World Step
- Page Life Cycle: Hello World Step (3.3.0.0)
- Page Life Cycle: Optimizing Page Load Performance
- People Sync: Overview
- People Sync: Adding Attributes to the People Directory View
- People Sync: Creating a Custom Data Source
- People Sync: Custom User Processor
- Using the Debug Panel
- AppManager: Enabling Load Balancing
- Deployment Manager: Overview
- Deployment Manager: Adding A Custom Site Definition
- Deployment Manager: Core Step Classes
- Deployment Manager: Custom Site Definition Components
- Deployment Manager: Custom Site Definition XML
- Deployment Manager: Custom Subsite Definitions
- Deployment Manager: Sample Step Code
- Deployment Manager: Supported Tokens
- Performance Considerations
- Production Settings: Disabling debug mode
- Akumina Foundation Site
- Akumina Multilingual vs Variations
- Caching: Modifying Site Caching
- Caching: Modifying Widget Caching Settings
- Managing Widget Load Priority
- Theme: Adding a New Rail Icon
- Theme: Changing the Theme of an Akumina Foundation Site
- Theme: Customizing Rail Icons
- Theme: Modifying an Akumina Foundation Theme