Wednesday, May 16, 2012

A lap around some SharePoint Architecture

Much has been written about the Client Object Model of SharePoint 2010 so I don't want to bore you with another post about that.

I would like to write something about JavaScript, SharePoint 2010, Web 2.0 and, why not!, how to use Knockout in SharePoint… WOW Open-mouthed smile

So let’s start why a little about theory about COM.

One image a thousand words:

Sharepoint Architecture

I got this image from MSDN off-course!!!

We will focus ourselves in what the red-square contains.

JavaScript OM

With JavaScript OM you can working inside the client browser to build new categories of application, for example rich html-javascript web part or form.
With JavaScript you work in a unmanaged area and you can use this om when you are working with the Server ribbon or insde sandboxed solutions.


It’s one of web services provided by Microsoft SharePoint 2010.
The following table lists and describes the available web services:


Ok now I show you a simple example:

- This is the result:

Alert from SharePoint Javascript

- and this is the code

<script type="text/javascript">
var context = null;
var web = null;
var currentUser = null;

function getUserData() {
context = new SP.ClientContext.get_current();
web = context.get_web();
this.oCurrentUser = web.get_currentUser();
context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod), Function.createDelegate(this, this.onFailureMethod));

function onSuccessMethod(sender, args) {
var today = new Date();
alert('User Name:' + this.oCurrentUser.get_title() + '\n Login Name:' + this.oCurrentUser.get_loginName() + '\n Page URL:' + location.href);

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

function callUserData() {
ExecuteOrDelayUntilScriptLoaded(getUserData, "sp.js");
<input type="button" value="Get User Info" onclick="javascript:callUserData();" />

ok it’s nothing special but this post is useful for the next one where we will create our service…

see you guys!

No comments:

Post a Comment