Team blog of MCS @ Middle East and Africa

This blog is created by Microsoft MEA HQ near shoring team, and it aims to share knowledge with the IT community.With its infrastructure and development sides,It brings to you the proven best practices and real world experiences from Subject Matter Experts
Follow Us On Twitter! Subscribe To Our Blog! Contact Us

SharePoint Group Calendar, Adding default users

SharePoint Group Calendar, Adding default users

  • Comments 15
  • Likes

The Problem

One feature of SharePoint is to create a calendar and make it a group calendar. This allows the user to see the schedule of list of people at the same time on the same view as per the image below.

image

To configure the Calendar as a group Calendar you need to edit the List settings and then click on “List name, description and navigation” and finally select the radio button as per the image below.

image

So all this is SharePoint out of the box functionality. So where is the problem?

The problem is that to get the view of all calendar of your work group every time you open the calendar view you need to add each one of them individually! And I could not find any way to persist this information so that it would open the calendar view automatically with the people added as per the list you see in the first image. So lets get to work.

The Solution

The way I fixed this is using Java script.

To be able to do this I used the following script.

var sel = SP.UI.ApplicationPages.CalendarSelector.instance().getSelector(1, 'WPQ12');
sel.selectEntities(ret, true);

You need two things to be able to perform the above script, the ID of the calendar web part (WPQ12 above) and the XML script to be able to add the required individuals. The way to do this is to follow the following steps:

Step 1: Getting the XML to add the required users

  1. Install and start Fiddler
  2. Click on the ribbon on the small arrow below “people” then “Add Person or Group”
    image
  3. This will give you the dialog to select the users, add all required users to be added by default to the Calendar view and then click “Ok” as image below
    image
  4. See Fiddler log to find an entry to add the users as per the below.
    image
  5. Then click on the response as text view you will find the Entities string as per the image below.
    image
  6. Copy this text to be used later in your script.

Step 2: Getting the web part ID

  1. Open the page with the calendar web part
  2. Open the IE developer tools (F12)
  3. Click on the selector arrow and then on the calendar web part (most top level)
  4. In the developer tools view you should see Id of the web part as below
    image

Step 3: Create the required script file

  1. Use the information gathered to construct a JS file as below

function _firstTime() {

//need to select the calendar tab so we can override the onlick method on some of the buttons.
SelectRibbonTab('Ribbon.Calendar.Calendar', true);

//give the ribbon time to load
setTimeout('_doWireUp();',2000);

}

function _doWireUp()
{
//change the onclick event for the group buttons to make sure it reloads our default group
var weekElem = document.getElementById('Ribbon.Calendar.Calendar.Scope.WeekGroup-Large');
if(weekElem)
weekElem.onclick = function() {setTimeout('_setDefaultResources();',1000);return false;};

var dayElem = document.getElementById('Ribbon.Calendar.Calendar.Scope.DayGroup-Large');

if(dayElem)
dayElem.onclick = function() {setTimeout('_setDefaultResources();',1000);return false;};

_setDefaultResources();
}

function _setDefaultResources() {

// This is the entities XML from step1
    var ret ='\u003cEntities c…………………………………………………………………………………………………………..\u002fEntities\u003e';

// Put here the web part ID from step 2

        var sel = SP.UI.ApplicationPages.CalendarSelector.instance().getSelector(1, 'WPQ12');
        sel.selectEntities(ret, true);
}

ExecuteOrDelayUntilScriptLoaded(_firstTime, "sp.ribbon.js");

  1. Save the file as cal.js (any name)

Step 4: Configure the web page

  1. Upload the JS file to any accessible location on SharePoint such as the styles library
  2. Check it in and publish it if required
  3. Edit the page with the calendar web part and add a content editor web part to the bottom of the page
  4. Edit the source of the content editor web part and add the following line
    <script src="/sites/<your site name>/Style%20Library/ctrl/cal.js" type="text/javascript"></script>
  5. Save the page and then reload it.
  6. See the magic happen :)
Comments
  • Hi I am unable to find the var ret by using fiddler any detail description how to find or any other alternate solution to this will be higly appreciated.

    Thanx in advance.

    Regards,

    Sabby

  • @Sabina - You may see "Response is encoded and may need to be decoded before inspection.  Click here to transform."  Above the Text view.  Click that box.

    You may also need to go into Fiddler Options, and select "Decrypt HTTPS traffic"

    I'm still struggling with Step 4, myself ...

  • Hi, I'm unable to add script content editor (Step 4). getting error message as " tags are not supported in html..." can anyone please explain me how to add JS script in content editor....

  • Follow this link to link the js file via a content editor web part. http://zepeda-mcmillan.blogspot.de/2011/03/displaying-default-resources-on-group.html

  • You should use the ID as 'WPQ2' to make it work.

    var sel = SP.UI.ApplicationPages.CalendarSelector.instance().getSelector(1, 'WPQ2');

    Thanks for the detailed post !! It works !!

  • I tried setting this up but when I look at the IE Dev Console I see an error sayin "Unable to get property 'selectEntities' of undefined or null reference"

    Followed the steps provided and got the XML but doesn't seem to be rendering, help!

  • This worked great! One question though, when you switch to other views such as "Day", "Week", or "Month" and then go back to the "Week Group" view, the set of default users are no longer there. Can this be worked around as well? Thanks!

  • When I add the users and click OK, I don't get any new entries in Fiddler. As far as I can tell, it's definitely connected to the IE window in question, as an entry appears when I click to bring up the "add users" window (Host= Tunnel to; URL = our sharepoint address; Process = iexplore).

    Any ideas why this might be? Thanks!

  • thank you

  • It's possible apply such functionality in recurrent events? i'm trying in sharepoint code behind, but i have a lot of problems for make him possible, any help will be much appreciated.

  • it works well. Its a magic Thanks

  • Thank you very much for this post!! Works well and loads all resources at load time. You the man.

  • It works for me one week but after I installed last updates for Windows and sharepoint 2013 foundation it stopped working and I can't fix it :( have you any idea what I should to do? just uninstall last updates?

  • WOW how ridiculous!!!! This is something that should work out of the box and you need coding for this?????

    MS WAKE UP!!!!

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment