How to Update Multiple Calendar Events

Update Multiple Calendar Events

Overview

This article explains how to modify / update multiple existing events in Calendar using Tizen platform device API's. This article applies only for systems based on Tizen platform.

Pre-conditions

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

For this example, Open the config.xml file then choose the "Feature" tab and add below features to use the Calendar APIs in your applications.

Update multiple calendar events

You can enable your application to update multiple calendar items using the updateBatch() method.

To update multiple existing events you need to follow the below steps:

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

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

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

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

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

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

In this example, all the events are retrieved because no filter is used in the find() method. The onEventSearchSuccess() callback changes the description parameter of the first two events, and update the events using the updateBatch() method.

Here updateEventsSuccess and errorCallback are two callback methods to show success and error message.

// Define the event success callback.
function onEventSearchSuccess(events) {
    //Here we are modifying description only.
    events[0].description = 'New Description 1';
    events[1].description = 'New Description 2';
    console.log("The description of first two item are updated!");
    // Update the first two existing event.
    myCalendar.updateBatch( events.slice(0,2), updateEventsSuccess, errorCallback );
}
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 find() method.