How to Update Recurring Calendar Event

How to Update Recurring Calendar Event Tutorial

Description

This article explains how to modify / update an existing recurring event in Calendar using the Tizen platform device API's in your applications. The article applies only for systems based on Tizen platform.

Pre-conditions

Use the Calendar API methods, you must declare the necessary features in the config.xml file.

Update Recurring Calendar Event

To update an existing event you need to follow the below steps:

  • Retrieve the calendar instance.
  • Retrieve calendar event(s).
  • Identify the event to be updated.
  • Save the updated event.

The default calendar instance is retrieved using the calendar.getDefaultCalendar method.


$ var myCalendar = null;
// Get the default calendar
$ myCalendar = tizen.calendar.getDefaultCalendar("EVENT");

By using Calendar.find method you can fetch complete or partial (based on filters) list of events in default calendar. In this example onEventSearchSuccess()method is registered as a success callback and onError() method is registered to handle errors.


//Fetch all events in default calendar
$ myCalendar.find(onEventSearchSuccess, onError);

You can specify the filter criteria using a filter, and a sorting order for the search operation through the filter and sortMode parameter of the Calendar.find method.


// Define the event success callback.
$ function eventSearchSuccess(events) {
    updateEvent(events[0]);
}

//The error callback
$ function onError(e) {
    console.log(e.message);
}

By using Calendar.update method you can update existing calendar item. The Calendar.update method takes two parameters; a calendar item to be updated, and a boolean value.

The boolean value indicates if all occurrences of the calendar item needs to be updated or not.

With an assumption that the first event of the event array is a recurring event we are procedding with the below updation process.

Update Single Instance Calender Recurring Event

In order to update a single instance of a recurring event, get the list of event instances by calling ev.expandRecurrence method. Once you receive all the event instances, call myCalendar.update() method with the event instance which needs to be updated and setting the updateAllInstances flag to "false".


// The error callback
$ function errorCB(response) {
   console.log( 'The following error occurred: ' + response.name);
}

// The expand success callback
$ function eventExpandSuccessCB(events) {
   events[1].summary = 'updated the summary';
   myCalendar.update(events[1], false);
}

$ function updateEvent(ev) {
// Expand the recurring event to get its instances
   ev.expandRecurrence(
      new tizen.TZDate(2012, 2, 1),
      new tizen.TZDate(2012, 2, 15),
      eventExpandSuccessCB,
      errorCB );
}

Update all Instances of Recurring Calendar Event

To update all the instances of recurring calendar event, call myCalendar.update() method with calendar event which needs to be updated and setting the updateAllInstances flag to "true".


//Update all the instaces of recurring event.
$ function updateEvent(ev) {
   myCalendar.update(ev, true)
}