Tag Archives: Calendar

Configuring SharePoint Calendar Overlay using Powershell

When comes to deployment, my always first rule is to automate the deployment steps.

You could always use site backup and restore for deployment. But that is not my preference, always. Simply because you can’t do this every time when you hit a problem or when you need to reconfigure the whole site.

Well, after some tracing on the Calendar list object class. I found the CalendarSetting property of calendar list.

Unfortunately, there isn’t a fully integrated API for you to configure SP calendar overlay. You have to parse the calendar setting in XML structure yourself. But that really isn’t bad.

You simply have to follow the structure as shown…

<AggregationCalendars>
 <AggregationCalendar Id='%%RANDOM GUID%%' Type='SharePoint' Name='%%VIEW NAME%%' Description='' Color='2' AlwaysShow='True'
 CalendarUrl='%%Calendar URL%%'>
  <Settings WebUrl='%%WEB URL%%' ListId='%%LIST ID%%' ViewId='%%VIEW ID%%' ListFormUrl='%%DISPLAY FORM URL%%' />
 </AggregationCalendar>
</AggregationCalendars>

Where

%%RANDOM GUID%% : GUID e.g. “{76018083-3ed1-4a4c-b332-734106113448}”
%%VIEW NAME%%: View Name
%%Calendar URL%%: URL to the calendar that you want to overlay. e.g. “/Lists/My Calendar/calendar.aspx”
%%WEB URL%%: URL of your SharePoint site.
%%LIST ID%%: Calendar List ID that you want to overlay.
%%VIEW ID%%: View ID of the Calendar that you want to overlay.
%%DISPLAY FORM URL%%: Display Form URL of the Calendar e.g. “/Lists/My Calendar/DispForm.aspx”

Note the Color attribute for  AggregationCalendar, this attribute takes in the index number of the colour choices (you can refer to the SharePoint Calendar Overlay page for this)

Toggling SharePoint 2010 Calendar View using JavaScript

Calendar is a very common used  module in SharePoint, it comes with 3 OOTB views namely Daily, Weekly and Monthly. Toggling between these views can be easily done using Ribbon button provided. However, there would be cases where you need to run your own JavaScript, perhaps to have a custom button to toggle the views of your calendar.

SharePoint has a in-built javascript function MoveDate which takes in a single parameter that is the view mode to be toggled.

For example


MoveDate('day')

This method simply toggle the current calendar control to ‘Daily’ view. Likewise, passing ‘week’ and ‘month’ will toggle the calendar to weekly and monthly view respectively.

This method however, doesn’t provide the flexibility to specify which calendar you want to toggle view. Imagine if you have more than 1 calendar control added into one single page. This method will just toggle the first loaded instance of calendar control. That’s not good.

Having digging deeper to the SharePoint javascript, there is a hidden function called ‘_MoveToDate(a,b,c)‘ which does the trick. Well I personally do not know what is parameter a for, however, parameter b is the view mode and c is the calendar instance id.

Making use of parameter b and c is good enough to get you toggling view of a specific calendar

That is, making a js call _MoveToDate(null,’day’,’the calendar id‘) will toggle the respective calendar control with ‘the calendar id’ to Daily view.

Now the second question is how to actually retrieve the so-called calendar id? To get that, it requires a little bit of jQuery Selector knowledge (You can read up here). In my case, I added the toggle buttons (within a DIV tag) on top of each calendar control. With this, i would call my custom js ToggleCalendar function with this  as the parameter. Firstly, lookup to the parent DOM object of this and get the sibling <table> tag (SharePoint Calendars are encapsulated within HTML tables, check View Source if you like). After getting the Table DOM, lookup for TD tag with ID starts wth “WebPartTitle”, reason being is that the ID of the calendar is in this format “WebPartTitleXXXX” where XXXX is the calendar instance ID and it is  usually WPQ1 or WPQ2 and so on depending on the number of calendar control you added to your page.

The code below simply showing how to retrieve a SharePoint calendar instance ID, and also to toggle its view to Daily view.


function GetInstanceID(obj)
{
$tdTag = $(obj).parent().siblings('table').find('td[id^="WebPartTitle"]');
var rawID = $($tdTag).attr('id');
return rawID.substring('WebPartTitle'.length);
}

function ToggleCalendar(obj)
{
_MoveToDate(null,'day',GetInstanceID(obj));
}

P.S. The code is with assumption that sp.js has been loaded successfully and you have also included jQuery file.

SharePoint Calendar Connect to Outlook is not working. Events not synchronized

I came across this funny issue when my client is trying to download/synchronize SharePoint calendar events to his MS Outlook.

Connect to Outlook Ribbon Button

The calendar instance is added successfully into his Outlook. However, all the events are not populated and the following message shown in the outlook status bar.

Outlook Send/Receive Error

Resolution

Execute the following script via SharePoint Powershell. Kindly change the calendarName to your calendar name.


#Here we go.

$web = Get-SPWeb http://yoursite

$calendarName = "My Calendar"

$calendar = $web.Lists[$calendarName];

$calendar.ExcludeFromOfflineClient = 0;

$calendar.Update()

This script simply enable the calendar to be available for offline client download.

Optionally, you can go to your Calendar’s List Setting > Advanced Setting and turn “Offline Client Availability ” on.

Offline Client Availability

Go back to your Outlook, Hit “Shift” + F9 to refresh the calendar.

TADA~

SharePoint Calendar on MS Outlook