Tuesday, June 21, 2016

Disappeared permissions for “Everyone except external users” in Sharepoint Online

Recently we faced with interesting issue in Sharepoint Online: for some parts of the intranet unique permissions were used. And for these securable objects we used special Sharepoint “group” (which is actually not real Sharepoint group) – Everyone except external users. One the same securable objects there were also permissions assigned to normal Sharepoint groups. After some time without any actions from our side permissions assigned to “Everyone except external users” group disappeared, but permissions assigned to normal Sharepoint groups not.

For now we solved it by using new Sharepoint group which has other AD group which in turn has all users in organizations and new employees are added there automatically (fortunately customer’s administrator had this group), but anyway this is quite interesting problem. So if you will face with the same issue or will find reason of this behavior please share it in comments.

Thursday, June 2, 2016

Remove duplicates in calendar overlays in Sharepoint

In Sharepoint calendar it is possible to have events of different categories and create separate views for each category. Also it is possible to create calendar overlays, i.e. combine these views to the single view where events from different categories will be displayed using different colors. However there is a problem with this approach that events in overlay will be duplicated by default. In this article I will show how to create these overlays and how to fix issue with duplicated events.

Let’s start from creating calendar overlays. At first we need to define event categories in List settings > Category field (choice) > specify needed categories. In our example we will use the following categories:

  • Meeting
  • Work hours
  • Business

After that create view for each category from the list ribbon Create view. For each view we create filter on Category field like shown on the following picture and use category as view name:

and repeat this step for each category. After that we can create calendar overlay. It is done also from ribbon Calendars overlay button which opens the following page:

As you can see by default it doesn’t contain any calendars. Click New calendar link here and specify Name, Color and View for the new layer in the calendar overlay. In order to populate calendar list and all created views we will need to create Resolve button first. Also it is good practice to use the same name for the overlay as view name (and as category name):

Also repeat this step for each category. After that our default calendar view will look like this:

Now let’s create one test event e.g. for Meeting category. It will look like this:

As you can see created event is duplicated in the view. In order to solve this issue we need to edit default calendar view as well and specify filter for Category field. We can set filter there that only events which don’t belong to any category should be shown there (Category is equal to “” (empty string)) or we may apply more complex filter and show only those events which don’t correspond to any mentioned categories. In last case if new category will be added in future events which correspond to this category will be displayed in the default view (unless separate view won’t be created and added to overlay. In this case you will need to add it to the filter of default view as well in order to not get duplicates again):

or

At the end calendar will look like this:

and as you can see there are no duplicates anymore.

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: 'http://example.com' 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:

[ui]
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);
   4:  
   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("http://example.com/sites/foo");
   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.

Friday, April 22, 2016

Get current Sharepoint list or document library via javascript object model

In server object model in Sharepoint there is simple way to get current list (i.e. list which is currently opened in browser window):

   1: var list = SPContext.Current.List;

In javascript object model it is not so obvious, but also possible. In order to get current list you have to use not very well known function GetCurrentCtx() defined in core.js. With this function we can get current list like this:

   1: var ctx = SP.ClientContext.get_current();
   2:  
   3: var currentCtx = GetCurrentCtx();
   4: var list = ctx.get_web().get_lists().getByTitle(currentCtx.ListTitle);
   5: ctx.load(list);
   6:  
   7: ctx.executeQueryAsync(
   8:     Function.createDelegate(this, function (sender, args) {
   9:         // use list here
  10:     }),
  11:     Function.createDelegate(this, function (sender, args) {
  12:         console.log("Error occured: " + args.get_message() }));

In this example the main difference between context created with SP.ClientContext.get_current() and context returned from GetCurrentCtx() is that last one has ListTitle property set to title of the current list or document library. Having it we can easily get list object from the web. Also this context contains other useful properties like listBaseType, listName, listTemplate and listUrlDir.