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.
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.
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
- Install and start Fiddler
- Click on the ribbon on the small arrow below “people” then “Add Person or Group”
- 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
- See Fiddler log to find an entry to add the users as per the below.
- Then click on the response as text view you will find the Entities string as per the image below.
- Copy this text to be used later in your script.
Step 2: Getting the web part ID
- Open the page with the calendar web part
- Open the IE developer tools (F12)
- Click on the selector arrow and then on the calendar web part (most top level)
- In the developer tools view you should see Id of the web part as below
Step 3: Create the required script file
- 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");
|
- Save the file as cal.js (any name)
Step 4: Configure the web page
- Upload the JS file to any accessible location on SharePoint such as the styles library
- Check it in and publish it if required
- Edit the page with the calendar web part and add a content editor web part to the bottom of the page
- 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>
- Save the page and then reload it.
- See the magic happen

|
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
Hi, I’m unable to add script content editor (Step 4). getting error message as "
thank you
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 …
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!
Pingback from Create a color coded group calendar for SharePoint Tutorial
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!
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!!!!
Ridiculous what a simple function, why doesnt it work at the click of a button and why on earth would you only want to do this "temporarily" as MS put it.
Cant belive all this work for something that should be out of box (as above)
I have SharePoint online and I am not able to get this to work. Does this script not work with Office 365?
Great work you did!
I have a question regarding all this cool functionality. Is there a way to show a "Month Group" view??
There are "Day Group" and "Week Group", and my users would be happy to see all the events that are going to happen in the month at the same time. Something like a ribbon with the text "Month Group"…
Thank you
Hi Its Working fine for me..But the problem is Whenever i am creating new item in calendar list,By default all resources are selected.How can i overcome this issue?
Thanks for this helpful information I agree with all points you have given to us. I will follow all of them.
http://staygreenacademy.com">SharePoint 2013 Developer training Online
Simply superb explanation about SharePoint Group Calendar, Adding default users.
http://staygreenacademy.com/sharepoint-training/
Does this work on Office 365 (SharePoint online)?? Thanks
Yes..it works on SharePoint online.
I am able to see only two users
hoping people still follow this post. Same issue as michszym. This script doesn’t seem to work after the lastet round of Sharepoint updates. Any ideas as I really need to find a way for this to work.
Wow, it works like a charm!
Sorry guys, I’m not a programmer, I did follow all steps and not able to make it work, I did found both required codes from step 1 and 2, I uploaded the .js file to style library, help?
Thanks for the post. It works but there are two issues I would llike to ask;
First, everytime I add a specific group from "People Selector", somehow I see system account as well.
Second, When I add calendar to a page as web part, it does not show any content.
Thanks.