Complete Guide to Making and Parsing REST calls using SharePoint Designer 2013

Recently I needed a sequential workflow that makes a REST call to another website (non-SharePoint), retrieves some JSON data, parses it, and makes decisions based on that data. Oh, and I’m not allowed to use Visual Studio in this case, it has to be SharePoint Designer (ugh). Continue reading Complete Guide to Making and Parsing REST calls using SharePoint Designer 2013

Read a SharePoint list using JavaScript

There are countless ways to read data from a SharePoint list, and also myriad methods to do this in JavaScript, but I’m going to document this one way as a place to get started, and a published function I can refer back to if needed!

First consider the following: Reading SharePoint list data using JavaScript requires the SP.js file to be loaded already. So, we should be putting this function inside of a $(document).ready(function())}; and if needed inside an ExecuteOrDelayUntilScriptLoaded(functionName, ‘sp.js’); Once in there, it would look something like this:

function readFromList() {
    var query = new SP.CamlQuery();
    var clientContext = SP.ClientContext.get_current();
    var oList = clientContext.get_web().get_lists().getByTitle('List Name');
    var items = oList.getItems(query);
    clientContext.executeQueryAsync(function () {
        if (items.get_count() > 0) {
            var enumerator = items.getEnumerator();
            while (enumerator.moveNext()) {
                var listItem = enumerator.get_current();
                var field = listItem.get_item('Field Name');
    }, function(sender, args) {

I’ll go over each line to explain what’s happening:
var query = new SP.CamlQuery(); – this is preparing a CamlQuery object using SP.js (which is why it’s important to wait for it to be loaded!)
query.set_viewXml – Here’s where you define your CAML query using normal CAML syntax. In the above scenario, it will return the Title field from all items in the list.
var clientContext = SP.ClientContext.get_current(); – this establishes a client context object using the current Site Collection.
var oList = clientContext.get_web().get_lists().getByTitle(‘List Name’); – this creates an object that references the specific list in the specific web you wanted to pull items from.
var items = oList.getItems(query); – this is saying get the items from the list object based on the query defined above.
clientContext.load(items); – you’re now telling the object model to prepare to execute the following object by loading it into the client context.
clientContext.executeQueryAsync – ok, here you actually execute the query you so dutifully prepared just a moment ago. This operation expects a “Success” function and a “Failed” function to be passed in or referred to somehow. The success function will be what you want to do once the query is done executing. The failed function will be how you want to handle any issues.

In the above example, the success function looks like this:

if (items.get_count() > 0) {
            var enumerator = items.getEnumerator();
            while (enumerator.moveNext()) {
                var listItem = enumerator.get_current();
                var field = listItem.get_item('Field Name');

What this is doing is looping through the results of the query and reading each one. The key is, to read a field value the syntax is listItem.get_item(‘Field Name’). Again, lots of ways to read field data, especially system fields like ID, this is just one example.

To handle errors I simply have whatever the error message is log to the console. At this point you can do what you like with the resulting data: put it in a string array and read it later, push it out to the page, make decisions based on the results, etc. Hope this helps!

Manage Created & Modified info on custom form in XSLT

Just wanted to write this down so I don’t forget how to do this, if this helps someone else out even better!

If you’re wanting to access the Created By, Created On, Modified By and Modified on information on a custom list form in SharePoint 2010 or 2013, you can do this using the SharePoint:CreatedModifiedInfo control and use the CustomTemplate element, like so:


SharePoint uses the field names Author, Created, Editor and Modified to refer to the following:

Author: Created by
Created: Date Created
Editor: Modified by
Modified: Date last modified

You can include any combination of these fields and any other HTML/CSS to adjust the layout as needed either inside or outside of the CreatedModifiedInfo control. If you want to separate out the fields into separate areas of the page, you will need to repeat the control pattern of SharePoint:CreatedModifiedInfo->CustomTemplate->FormField for each section.

Hope this helps!

The data source control failed to execute the insert command

While working on a custom form the other day, we noticed the form that was working fine was suddenly throwing the following error:
“The data source control failed to execute the insert command”

Without anything to go off of we started comparing version history in the form, comparing source control versions, searching online, nothing really worked. It ended up being a combination of several things.

First, make sure your XSLT databinding parameter matches the type of databinding you’re doing. For example, there are three types of databinding parameters available in the SharePoint:FormField control:
i = Insert Used for NewForm pages
u = Update Used for EditForm pages
d = Delete Self-explanatory

Therefore, if you’re adding a FormField control to a NewForm page, you wouldn’t want to use the ‘u’ parameter in the ddwrt:DataBind() function, it should be as follows:

Likewise, your EditForm page would look like this:

In addition to this, the other issue was there were site columns that were deleted but still being referenced in the form template. Either locating those site columns in the template and commenting them out or removing them altogether, or re-adding them to the site columns page solved the problem.

Another possibility I found was after applying an update (or through changes from troubleshooting) you may find the SPDataSource for the form’s DFWP is changed to:

The DataSourceMode is supposed to be:

There could be other reasons for this error, feel free to add them to the comments below. Hope this helps!

Windows 8.1 Update 1

Today at Build 2014 Microsoft announced the availability of Windows 8.1 Update 1 on April 8th to the general public, but it’s available now to MSDN subscribers. Not wanting to waste any of the precious resources made available us MSDN folks, I promptly downloaded the bits and put them on my Surface Pro. Installation required applying 5 Feature Packs, and one system restart, total of about 15 minutes. Very simple, and none of my personal info or settings on the machines were modified or reset. Here’s my initial findings:

The Power icon now appears on the Start screen in the top right corner, next to your account picture. Nice quick way to Shut Down or Restart your machine without swiping from the right, tapping Settings, tapping Power, tapping Shutdown/Reset.

Screenshot (44) Screenshot (45)

The Store icon now appears in the taskbar by default, giving end-users the opportunity to find apps even quicker by having the store icon more visible other than on their Start screen or buried in their Apps somewhere when they remove it from their Start screen.
Screenshot (46)

Hold down the Ctrl key and left-click (or tap) on multiple tiles to select them as a group, for removal, movement, etc.
Screenshot (47)

Right-click on the tiles and get the traditional context menu instead of having to use the app bar at the bottom. Much more familiar feel to experienced Windows users
Screenshot (48)

System resources were well within normal limits too. Low CPU utilization, avg memory consumption, and very low overhead (only 770 MB for all 5 feature packs combined!)
Screenshot (49)

UPDATE: After installing the RT (ARM) version of Update 1, it seems all of the same changes apply with the exception of the Power icon at the top right of the Start screen. It’s not there, not sure if it was deliberately left off of the RT build or if it’s some security setting I have on my girls’ Surfaces. Either way, it’s a discrepancy. Everything else seems to be the same as far as I can tell.

Overall, so far so good! They also mentioned in a future release that the traditional Start menu was returning, as well as Cortana personal assistant integration from Windows Phone as well as other great features were coming. I’m very pleased that this was implemented in a series of feature packs instead of a major update requiring numerous restarts and altering of customized properties and settings. I’m looking forward to the next iteration with the additional changes and innovations!

Posts and ramblings about SharePoint, software development, and other things I thought were cool