Karine Bosch’s Blog

On SharePoint

New release of CAML Designer available with new functionality!


042813_0652_Newversiono1.png

This weekend we released a new version of the CAML Designer.We solved the bug that occurred when more than one TaxonomyField was selected in the Where clause; but we also include the following new functionality:

– The <Membership> element

– REST snippets including a CAML query

We are very proud with these new additions, and we hope you like it!

 

 The <Membership> element

The <Membership> element already exists for ages but it’s only now that we introduce it in the CAML Designer.

Whenever you select a field of user type in the Where clause, you will now get an additional radio button “Membership”:

User field

When you click the Membership option, you get an additional dropdown where you can select one of the following options:

  • CurrentUserGroups: this will retrieve all tasks that are assigned to groups to which the current user belongs.
  • SPWeb.Groups: this will retrieve all tasks that are assigned to groups.
  • SPWeb.AllUsers: this will retrieve all tasks that have been assigned to users and not to groups.
  • SPWeb.Users: this will retrieve all tasks that have been assigned to users that don’t belong to a specific group but that have been granted access to the site directly.
  • SPGroup: this will retrieve tasks that have been assigned to a specific group.

User field - membership

We’ve also foreseen a small description field that explains the selected option:

User field - membership CurrentUserGroups

When selecting the SPGroup option, another additional dropdown becomes available. This dropdown will list all groups:

User field - membership SPGroup

Selecting a group from this dropdown will retrieve all tasks that have been assigned to the selected group. The CAML query looks like the following:

   <Where>
      <Membership Type='SPGroup' ID='5'>
         <FieldRef Name='AssignedTo' />
      </Membership>
   </Where>

When you select the CurrentUserGroups option, the CAML query will look as follows:

  <Where>
      <Membership Type='CurrentUserGroups'>
         <FieldRef Name='AssignedTo' />
      </Membership>
   </Where>

For the SPWeb.Groups option, the CAML query looks like this:

  <Where>
      <Membership Type='SPWeb.Groups'>
         <FieldRef Name='AssignedTo' />
      </Membership>
   </Where>

For the SPWeb.AllUsers options, the following CAML query is generated:

  <Where>
      <Membership Type='SPWeb.AllUsers'>
         <FieldRef Name='AssignedTo' />
      </Membership>
   </Where>

And when you select the SPWeb.Users option, you will get the following CAML:

  <Where>
      <Membership Type='SPWeb.Users'>
         <FieldRef Name='AssignedTo' />
      </Membership>
   </Where>

Credits go to Christoper Clementen with his blog post: http://christopherclementen.wordpress.com/2012/08/27/caml-query-membership-attribute where he clearly explains how the <Membership> element works.

 

REST snippets executing CAML queries

A second new functionality are the REST snippets with CAML queries. In most cases you can use the well known REST requests using the select and filter criteria to retrieve list items. But there are a few cases where such a REST request will return an error. These cases are:

  • filtering on taxonomy fields
  • the <Membership> element

In these cases your REST snippet must include a CAML query. Additionally this REST request needs to be executed as a POST. This is well described in this blog post of CleverWorkarounds.

Such a REST snippet generated by the CAML Designer looks like this:

 

$.ajax({ 
   url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('Developers')/GetItems(query=@v1)?"
        + "@v1={\"ViewXml\":\"<View><ViewFields><FieldRef Name='Title' /><FieldRef Name='FirstName' /><FieldRef Name='Company' /></ViewFields>"
        + "<Query><Where><Eq><FieldRef Name='Technology' /><Value Type='TaxonomyFieldType'>SharePoint</Value></Eq></Where></Query></View>\"}", 
   type: "POST", 
   headers: { 
         "X-RequestDigest": $("#__REQUESTDIGEST").val(), 
         "Accept": "application/json;odata=verbose", 
         "Content-Type": "application/json; odata=verbose" 
   }, 
   success: function (data) { 
      if (data.d.results) { 
         // TODO: handle the data  
         alert('handle the data'); 
      } 
   }, 
   error: function (xhr) { 
      alert(xhr.status + ': ' + xhr.statusText); 
   } 
});

When filtering on membership, the REST snippet will look like this:

$.ajax({ 
   url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('Tasks')/GetItems(query=@v1)?@v1={\"ViewXml\":\"<View><Query><Where><And><Neq><FieldRef Name='Status' /><Value Type='Choice'>Completed</Value></Neq><Membership Type='SPWeb.Groups'><FieldRef Name='AssignedTo' /></Membership></And></Where></Query></View>\"}", 
   type: "POST", 
   headers: { 
         "X-RequestDigest": $("#__REQUESTDIGEST").val(), 
         "Accept": "application/json;odata=verbose", 
         "Content-Type": "application/json; odata=verbose" 
   }, 
   success: function (data) { 
      if (data.d.results) { 
         // TODO: handle the data  
         alert('handle the data'); 
      } 
   }, 
   error: function (xhr) { 
      alert(xhr.status + ': ' + xhr.statusText); 
   } 
}); 

Advertisements

May 22, 2014 - Posted by | CAML Designer, SharePoint 2013

3 Comments »

  1. Thanks for the credits 🙂 I’l try this update asap!

    Comment by Christopher Clement | May 23, 2014 | Reply

    • That would be very nice of you 🙂

      Comment by Karine Bosch | May 23, 2014 | Reply

  2. […] New release of CAML Designer available with new functionality! […]

    Pingback by SharePoint 2013: Recopilatorio de enlaces interesantes (XXXIII)! - Blog de Juan Carlos González en Geeks.MS | June 1, 2014 | Reply


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: