dataBridge > dataBridge Sharepoint Tips Blog > Posts > “The SharePoint 2010 EcmaScript Client Object Model: Part 1”
dataBridge Sharepoint Tips Blog
June 07
“The SharePoint 2010 EcmaScript Client Object Model: Part 1”

When SharePoint 2010 was released Microsoft had the foresight to include the ability to access the underlying SharePoint objects (lists, libraries, webs, site collections) at the client level vs. the SharePoint server object model.

SharePoint 2007 did give end users the ability to access data via web services but this was a relatively clunky way to get at these SharePoint objects (although the SPServices JavaScript library did make this somewhat easier – see http://spservices.codeplex.com/)

 
Now anyone who has a functional understanding of JavaScript can do some amazing things without having to resort to the awkward if not sometimes rigid walls put up by System Administrators.
 
Take a look at this sample JavaScript (from now on I’ll use that vs. Microsoft’s coinage of EcmaScript) code to see just how simple it is to access SharePoint web information.
 
                ExecuteOrDelayUntilScriptLoaded(getWebSiteData, "sp.js");
                var context = null;
                var web = null;
                function getWebSiteData() {
                                context = new SP.ClientContext.get_current();
                                web = context.get_web();
                                context.load(web);
                                context.executeQueryAsync(
Function.createDelegate(this, this.onSuccessMethod),
Function.createDelegate(this, this.onFailureMethod));
                }
                function onSuccessMethod(sender, args) {
                                console.log('web title:' + web.get_title() + '\n ID:' + web.get_id());
                }
                function onFaiureMethodl(sender, args) {
                                console.log('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
                }
 
       Now this code does nothing special, but does display the web title and GUID in the JavaScript console window.
 
Not really that exciting but next time we’ll go over what this code does, how it does it and then we’ll begin the task of creating a JavaScript slideshow from a SharePoint picture library.
 
By the end of this series you should be able to access a SharePoint list and do just about anything with it, including updating data. We’ll accomplish this by using real-world examples that you can use on your own SharePoint sites.
 

 

I will assume you have a fairly good understanding of SharePoint site collections, webs, lists/libraries and columns.

 

Guy Davis -
Developer

Comments

There are no comments for this post.

Add Comment

Title


Body *


Captcha *

 

Attachments

 

 About this blog

 
About this blog
Welcome to SharePoint Blogs. Use this space to provide a brief message about this blog or blog authors. To edit this content, select "Edit Page" from the "Site Actions" menu.