Archive for the ‘Client Object Model’ Category
SharePoint Client Object Model – Check user belongs to a Group – Disable controls in editfrm.aspx
Posted on: August 17, 2011
Just wanted to Share a Script which will help in checking if the Logged in User belongs to a SharePoint user group and based on it disable some controls in editfrm.aspx on Custom List. It uses JQUERY.
ExecuteOrDelayUntilScriptLoaded(disableControls, “sp.js”);
function disableControls()
{
clientContext = new SP.ClientContext();
groupCollection = clientContext.get_web().get_siteGroups();
group = groupCollection.getById(21); //The ID of the SharePoint user group
users = group.get_users();
clientContext.load(group);
clientContext.load(users);
currentUser = clientContext.get_web().get_currentUser();
clientContext.load(currentUser);
clientContext.executeQueryAsync(Function.createDelegate(this,
this.onQuerySucceeded), Function.createDelegate(this,
this.onQueryFailed));
RefreshCommandUI();
}
function onQuerySucceeded()
{
if(users.get_count() >0)
{
UserExistInGroup = false;
for(var i=0; i < users.get_count(); i++)
{
if(users.itemAt(i).get_loginName() == this.currentUser.get_loginName())
{
UserExistInGroup = true;
break;
}
}
}
if (UserExistInGroup)
{
var p=$(‘input[title=Priority'); //Name of the columns that needs to be disabled
var i=$('input[title=Range]‘); //Name of the columns that needs to be disabled
$($(p)[0]).attr(‘disabled’,false);
$($(i)[0]).attr(‘disabled’,false);
}
else
{
var p=$(‘input[title=Priority');
var i=$('input[title=Range');
$($(p)[0]).attr(‘disabled’,true);
$($(i)[0]).attr(‘disabled’,true);
}
}
function onQueryFailed(sender, args)
{
var p=$(‘input[title=Priority');
var i=$('input[title=Range]‘);
$($(p)[0]).attr(‘disabled’,true);
$($(i)[0]).attr(‘disabled’,true);
}
The method “GetItems” of the type “List” with ID {..} is blocked by administrator on the server
Posted on: May 13, 2011
Have you ever faced this error on a MOSS 2010 website. Here is a scenario that I came across.
We are launching a Public facing website which is built on top of MOSS 2010. When we are testing the site in QA environment enabling the Anonymous access on the Extended Web App, we started getting this error when we are accessing the lists using Client Object Model.
So basically this an error that we normally get when there is an Anonymous site which has Client Object Model used which is accessing the lists on the site.
Fix,
Open SharePoint 2010 Management Shell (Or Open Power Shell and Load MOSS Modules)
Insert command Get-ExecutionPolicy (This will show the current Execution Policy – Make a note of it).
$webapp = Get-SPWebApplication “<<your web URL which is having the issue>>”
$webapp.ClientCallableSettings.AnonymousRestrictedTypes.Remove([microsoft.sharepoint.splist], “GetItems”)
$webapp.Update()
Now that you have changed the settings, revert back the Execution Policy to what ever it was earlier.
Set-ExecutionPolicy <<What ever it was earlier>>
Hope this will help.
