SharePoint Developer Support Team Blog

The Official blog of the SharePoint Developer Support Team

How To: Make SharePoint Calendar events recurring by default

How To: Make SharePoint Calendar events recurring by default

  • Comments 4
  • Likes

 

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.

clip_image001[1]

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

clip_image003[1]

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

clip_image005

Comments
  • Hi,.

    I created on recurring event with End after 10 occurrences and I observed there are occurrences creating. What it might me the problem ?

    Can you please share if you have any info about this..?

    Thanks In advance

    Rajendra

  • Hi,.

    I created on recurring event with End after 10 occurrences and I observed there are 12 occurrences creating. What it might me the problem ?

    Can you please share if you have any info about this..?

    Thanks In advance

    Rajendra

  • Hi Rajendra,

    Thanks for the question.

    Is it happening on every calender list you have? Please try it in a different site collection if you could.

    You can also post the question to the sharepoint forum here to get a wider audience : social.msdn.microsoft.com/.../home

    Thanks

    Charls

  • Hi,

    I am trying to set default value of End by field. so can you please tell me how i can find HTML control for the text box??

    Thanx,
    Aniket

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