I have a standard CAML query (see below) that I would like to perform in SharePoint designer. How do I take this CAML query and retrieve it's data. Also where do I declare the list to run it against

<FieldRef Name="Title" />
<Value Type="Text">Test</Value>
<FieldRef Name="Created" Ascending="False" />

5 Answers 5


If you requirement is to simply check the results of the query then you can use a tool like U2U Caml Query Builder. This tool allows you to create and execute the queries on a given list without the need to write any code. Moreover, it also generates a sample managed client object model code and server object model code which can be used in applications like a console application.

However, if your requirement is to use the CAML Query in a SharePoint designer, then only having a query is not sufficient. You may need to write JavaScript client object model code inside the designer. The code will get the list and execute query against it and display the result. Example code:

function retrieveListItems() {
    var clientContext = new SP.ClientContext.get_current();
    var oList = clientContext.get_web().get_lists().getByTitle('YourListName');

    var camlQuery = new SP.CamlQuery();
        '<View><Query><Where><Geq><FieldRef Name=\'ID\'/>' + 
        '<Value Type=\'Number\'>1</Value></Geq></Where></Query>' + 
    this.collListItem = oList.getItems(camlQuery);

        Function.createDelegate(this, this.onQuerySucceeded), 
        Function.createDelegate(this, this.onQueryFailed)

function onQuerySucceeded(sender, args) {
    var listItemInfo = '';
    var listItemEnumerator = collListItem.getEnumerator();

    while (listItemEnumerator.moveNext()) {
        var oListItem = listItemEnumerator.get_current();
        listItemInfo += '\nID: ' + oListItem.get_id() + 
            '\nTitle: ' + oListItem.get_item('Title') + 
            '\nBody: ' + oListItem.get_item('Body');


function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + 
        '\n' + args.get_stackTrace());

SP.SOD.executeFunc('sp.js', 'SP.ClientContext', retrieveListItems);

You can create a page and using sharepoint designer and add the list view web part/ xsltlistview webpart you can use the CAML query and fetch the list data. Following is example of xsltlistview webpart to show the data based on CAML query.

<WebPartPages:XsltListViewWebPart runat="server" IsIncluded="True"
                        GhostedXslLink="main.xsl" FrameType="None" NoDefaultStyle="TRUE" ViewFlag="8"
                        Title="My Request" PageType="PAGE_NORMALVIEW" Default="FALSE"
                        __markuptype="vsattributemarkup" PartOrder="2"
                        ViewContentTypeId="0x" __designer:customxsl="fldtypes_Ratings.xsl" ListDisplayName="ProductList">
                <View Name="{78E6EC9D-1910-4B6D-9030-E88975FAA2EC}" 
                    Type="HTML" DisplayName="All Items" 
                     Level="1" BaseViewID="1" ContentTypeID="0x" ImageUrl="/_layouts/15/images/generic.png?rev=23">
                                <FieldRef Name="CreatedBy"/>
                                <Value Type="Integer">
                                    <UserID Type="Integer"/>
                        <FieldRef Name="LinkTitle"/>
                        <FieldRef Name="Product"/>
                        <FieldRef Name="Price"/>
                        <FieldRef Name="Quantity"/>
                        <FieldRef Name="Status"/>
                        <FieldRef Name="Supervisor"/>
                    <RowLimit Paged="TRUE">30</RowLimit>
                    <Aggregations Value="Off"/>
                    <XslLink Default="TRUE">main.xsl</XslLink>
                    <Toolbar Type="None"/>
                <ParameterBinding Name="dvt_sortdir" Location="Postback;Connection"/>
                <ParameterBinding Name="dvt_sortfield" Location="Postback;Connection"/>
                <ParameterBinding Name="dvt_startposition" Location="Postback" DefaultValue=""/>
                <ParameterBinding Name="dvt_firstrow" Location="Postback;Connection"/>
                <ParameterBinding Name="OpenMenuKeyAccessible" Location="Resource(wss,OpenMenuKeyAccessible)" />
                <ParameterBinding Name="open_menu" Location="Resource(wss,open_menu)" />
                <ParameterBinding Name="select_deselect_all" Location="Resource(wss,select_deselect_all)" />
                <ParameterBinding Name="idPresEnabled" Location="Resource(wss,idPresEnabled)" />
                <ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
                <ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(core,noXinviewofY_DEFAULT)" />
                <ParameterBinding Name="AddNewAnnouncement" Location="Resource(wss,addnewitem)" />
                <ParameterBinding Name="MoreAnnouncements" Location="Resource(wss,moreItemsParen)" />

I think SharePoint Designer is not meant for this .

First of all you need a List in your Sharepoint site for the CAML query to get the items from it.

How to create a List:http://www.sharepoint-journey.com/create-list-in-sharepoint-2013.html

Now there are two conditions:

  1. If you need all items in the List: No need of CAML then.

    SPList list = web.Lists["MyList"];

    SPListItemCollection items = list.Items;

  2. If you need specific items from the list:Use CAML query There are certain tools which you can install to test and see the results of your CAML query




I don't think that it's possible with SharePoint Designer. I highly recommend you using this tool (http://splistitemeditor.codeplex.com/) or this tool (https://spcamlqueryhelper.codeplex.com/). These tools will let you try your CAML queries and display your results in Gridviews.


In addition to utilizing the web parts, discussed above, you can also leverage the SharePoint Client Object Model/SPServices. There is a codeplex solution, CamlJs, which provides some ease to the process, and helps you build JS that will complete your desired solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.