Friday, May 20, 2016

One reason for The request uses too many resources error when create sub site in Sharepoint Online

Recently we faced with the following issue: when users with standard Manage hierarchy permission level (according to description of this permission level, user with these permissions “can create sites and edit pages, list items, and documents”) tried to create sub site in Sharepoint Online the following exception was thrown:

ServerException: Provisioning did not succeed. Details: Failed to initialize some site properties for Web at Url: '' OriginalException: The request uses too many resources.

StackTrace: at Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream) at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse() at Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryToServer(ChunkStringBuilder sb) at Microsoft.SharePoint.Client.ClientRequest.ExecuteQuery() at Microsoft.SharePoint.Client.ClientRuntimeContext.ExecuteQuery() at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery() at Microsoft.SharePoint.Client.ClientContextExtensions.ExecuteQueryImplementation(ClientRuntimeContext clientContext, Int32 retryCount, Int32 delay)

We tried to increase server resource quota, but it didn’t help. The problem existed both for sites created from custom SP app and for standard site templates.

In order to avoid this error the following steps can be done: go to Site settings > Site permissions > Permission levels > Manage hierarchy and check the following permissions (by default they are unchecked for Manage hierarchy permission level):

  • Apply Themes and Borders – Apply a theme or borders to the entire Web site
  • Apply Style Sheets – Apply a style sheet (.CSS file) to the Web site

So they will look like this:

After that hierarchy managers should be able to create sub sites.

Tuesday, May 10, 2016

How to set author displayed in Mercurial commits on Windows

Note for readers: in this article I will show how to configure author name on Windows PC for future Mercurial commits. It won’t contain information how to change author for commits which were already done.

If you work with different repositories sometime it may be necessary to change Author field displayed in commits history. On Windows PCs in order to do that go to C:\Users\{username} and edit mercurial.ini file:

username = developer

In this example “developer” is the user name which will be displayed in Author field. If you will now open TortoiseHG Workbench tool new user name should be displayed in Author column.

Wednesday, May 4, 2016

How to get user’s login name in Sharepoint Online via javascript object model

In this post I will show how to achieve simple task: get login name of the user via javascript object model. The main misleading thing is that in current version of MSDN documentation SP.User object contains only the following properties:

- email
- groups
- isSiteAdmin
- userId

You might think that email property can be used as login name (because in Sharepoint Online users are authenticated using their email – organizational or external connected to MS live id). However some time ago the following note was added to this property in MSDN:

This property is not available in SharePoint Online.

So how to get login name then? The answer is to use not-documented loginName property which will return you login name of the user in claims format. E.g. the following example shows how to get login name of the current user via javascript object model in Sharepoint Online:

   1: var ctx = SP.ClientContext.get_current();
   2: var currentUser = ctx.get_web().get_currentUser();
   3: ctx.load(currentUser);
   5: ctx.executeQueryAsync(
   6:     Function.createDelegate(this, function (sender, args) {
   7:         console.log("Login name: " + currentUser.get_loginName());
   8:     }),
   9:     Function.createDelegate(this, function (sender, args) {
  10:         console.log("Error: " + args.get_message()
  11:     }));

Hope that this information will help someone.

Problem with creating cross-site collection SP.ClientContext and metadata filters in Sharepoint document libraries

Recently we faced with interesting problem in Sharepoint Online site: in one of document libraries we had custom ribbon button. Javascript handler of this button created SP.ClientContext object for different site collection and retrieved some data from this site collection:

   1: var otherSiteCtx = new SP.ClientContext("");
   2: var otherSiteWeb = otherSiteCtx.get_web();
   3: otherSiteCtx.load(otherSiteWeb);
   4: otherSiteCtx.executeQueryAsync(
   5:     Function.createDelegate(this, function (sender, args) { ... }),
   6:     Function.createDelegate(this, function (sender, args) {
   7:         console.log("Get site failed: " + args.get_message());
   8:     }));

It worked until we activated Metadata navigation and filtering feature and added Metadata filter to this document library. After that code above started to throw exception:

Unexpected response from server. The status code of response is '403'. The status text of response is 'FORBIDDEN'

In order to avoid the problem we had to disable metadata filter for this document library, i.e. in doclib settings > Metadata navigation settings remove all fields from filter list:

After that javascript handler started to work again. It looks like issue in Sharepoint internal javascript implementation. If you know better solution, please share it in comments.