Error to used SP.ClientContext using javascript Client Object Model

April 18, 2011

Hi all. Last week I got error, when I used Java Script code for get data of list SharePoint.



CommandAction="javascript:function Get_Selected_Item_ID()
var selectedItems = SP.ListOperation.Selection.getSelectedItems();
var ListId = SP.ListOperation.Selection.getSelectedList();
for(var i in selectedItems)
alert(‘Item ID = ‘ + selectedItems[i].id);
alert(‘items = ‘ + items);
var ctx = SP.ClientContext.get_current();
var web = ctx.get_web();
alert(‘CTX = ‘ + ctx);
alert(‘CTX URL = ‘ + ctx.Url);
alert(‘WEB = ‘ + web);
alert(‘WEB URL = ‘ + web.Url);
Get_Selected_Item_ID()" />


After, I got error:

"Permission denied" error while trying to get SP.ClientContext using javascript Client Object Model on load event


The issue occurs because the scripts required by the Client OM are not loaded before the execution of the Javascript code.


var web;
function getRelativeUrl()
alert(‘web.get_serverRelativeUrl() ‘ + web.get_serverRelativeUrl());
function getFailed()
alert(‘Failed to retrieve the server relative URL.’);
function initialize()
var clientContext = new SP.ClientContext.get_current();
web = clientContext.get_web();а
clientContext.executeQueryAsync(Function.createDelegate(this, getRelativeUrl), Function.createDelegate(this, getFailed));
}" />


More information this –


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: