CAML query is supported in BindTuning Web Parts to map data from SharePoint lists. You can create a query to target specific elements in a SharePoint list.
Before we start
If you’re using SharePoint 2013/2016/2019 and Online, you can use a 3rd party free software for creating the query, like U2U Caml Query Builder for SharePoint 2013 (Standalone Edition).
This tool will auto-generate the query, after passing the necessary values.
Use Case
Let's say, for instance, we were wanting to filter our Site Pages document library, so as to retrieve Modern News Posts, while excluding the remaining pages.
After fine-tuning our source, we need a mechanism to only show News Posts created in the last 90 days.
Although it may seem daunting at first, we can utilize U2U's CAML Query Builder, so as to visually create our constraints, as well as leverage the built-in CAML query editor provided by BindTuning's web parts, enforcing those same parameters.
Creating a Query
To create your own custom CAML Query, follow the steps below:
- The first step will consist in connecting our SharePoint site collection to U2U's interface;
- Locate the list and/or document library we want to create filters for;
- After successfully accessing our list, we need to create a New Query. This query will accept the underlying columns of the list we are connecting to.
- Utilize the visual interface so as to create your own query.
After successfully creating our custom query, the editor will automatically generate the corresponding structure, as seen below:
<View> <Query> <Where> <And>// have to meet this 2 conditions <Eq> //Equal <FieldRef Name='PromotedState' /> <Value Type='Number'>2</Value> </Eq> <Leq> //Lower or Equal <FieldRef Name="Created" /> <Value Type="DateTime" Offset="-90"> // -90 days from today <Today/> </Value> </Leq> </And> </Where> <OrderBy> <FieldRef Name='Created' Ascending='False'></FieldRef> // Most Recent to older created element </OrderBy> </Query> <RowLimit>3</RowLimit> // Number of items that you need to show </View>
Add Query to BindTuning's Web Parts
Most of BindTuning's Web Parts will allow you to add your CAML Query directly, when configuring your source options.
To add the previously created CAML Query to BindTuning's News Web Part follow the steps below:
- Add a BindTuning News Web Part to the Page and select the option Configure;
- Under List Settings click on Manage News;
- Select Add List and connect to the necessary list or document library (i.e, Site Pages);
- Under Filtering Options select CAML Query, and paste the query created above.
Comments