SharePoint Client Object Model (ECMAScript) #1 – Get Context Object


SharePoint Client Object Model (ECMAScript) provides the capabilities of SharePoint Server Object capabilities at the client side. In this tutorial, let me show you how you can play around with the Client Object Model through IE Developer Toolbar.

Check the screenshot below, to know what we are trying to achieve here:

Below is the function that i have used:

function getWebProperties() {
var ctx = new SP.ClientContext.get_current();
this.web = ctx.get_web();
ctx.load(this.web);
ctx.executeQueryAsync(Function.createDelegate(this, this.onSuccess),
Function.createDelegate(this, this.onFail));
}
function onSuccess(sender, args) {
alert(‘web title:’ + this.web.get_title() + ‘\n ID:’ + this.web.get_id() +
‘\n Created Date:’ + this.web.get_created());
}
function onFail(sender, args) {
alert(‘failed to get list. Error:’+args.get_message());
}

ExecuteOrDelayUntilScriptLoaded(getWebProperties, “sp.js”);

The above ECMAScript access the SharePoint’s client context object. It is essential to note that “SP.js” is loaded before this script execution occurs. This is the reason for using the “ExecuteOrDelayUntilScriptLoaded” function.

3 thoughts on “SharePoint Client Object Model (ECMAScript) #1 – Get Context Object

  1. An interesting dialogue is price comment. I believe that it is best to write more within this topic,
    it won’t be described as a taboo subject but generally everyone is not sufficient to dicuss on such topics. To a new location. Cheers

  2. you’re in fact a good webmaster. The site loading speed is amazing. It kind of feels that you’re doing any distinctive trick.
    Furthermore, The contents are masterpiece.

    you’ve done a magnificent activity with this subject!

Feel free to leave a reply here...

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