First published on TECHNET on Apr 11, 2013
This blog post is a contribution from Charls Tom Jacob, an engineer with the SharePoint Developer Support team.
By default, new events added to SharePoint calendar list are not set to be recurring. If all the events users create are going to be recurring, it would be convenient to have this checkbox checked by default, along with some default values populated for the recurrence details.
This can be easily achieved by doing some customization to the list form using SharePoint Designer and JavaScript.
Follow the steps below:
1. Open the list in SharePoint designer
2. Clicks Forms section and click New Item Form from the ribbon
3. Set it as the default form
4. Edit this file in advance mode. Place the following JavaScript after the PlaceHolderMain:
<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">
JavaScript code to set the Recurrence checkbox checked and to set some default value for recurrence.
<script language="javascript" type="text/javascript">
// Push these methods for execution after the page load
_spBodyOnLoadFunctionNames.push("EnableRecurrence");
_spBodyOnLoadFunctionNames.push("ChangeRecurrenceSettings");
// Utility method to get the HTML element for a sever side control based on a partially matching name
function findHtmlControl(ctrlName) {
var inputs = document.getElementsByTagName("input");
for (var i = 0; i < inputs.length; i++) {
if(inputs[i].id.indexOf(ctrlName) > 0)
return inputs[i]
}
}
function EnableRecurrence() {
// Server generated Id for the checkbox would look like this :
// ctl00$m$g_86f2fc9c_f288_4ea5_8967_96c53e5a8aa5$ff71$ctl00$ctl00$RecurrenceField
var RecurrenceField= findHtmlControl("RecurrenceField");
if(RecurrenceField.checked == false)
{
// Set the checkbox to checked
RecurrenceField.checked = true;
// Fire the click event which initiates a post-back which will display the recurrence details section
RecurrenceField.onclick();
}
}
function ChangeRecurrenceSettings() {
var repeatInstances= findHtmlControl("repeatInstances");
var endDateRangeType= findHtmlControl("endDateRangeType1");
// Select the "End after" option button
if(endDateRangeType != null)
{
endDateRangeType.checked = true;
}
// Set number of occurrences to 12 instead of the default 10
if(repeatInstances != null)
{
repeatInstances.value = 12;
}
}
</script>
5. Save the changes and navigate to the SharePoint site, create a new Event. The form would open with recurrence checkbox checked and “End after” set to 12
Welcome to the SharePoint Blog! Learn best practices, news, and trends directly from the SharePoint team.