How to Delete Multiple Calendar Events

Delete multiple Calendar Events

Overview

This article explains how to delete multiple events from 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.

Delete multiple calendar events

You can enable your application to delete multiple existing calendar item using the removeBatch() method. This method takes "event id's" as a parameter.

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

  • Retrieve the calendar instance.
  • Retrieve calendar event(s).
  • Identify the events to be deleted.
  • Deleted the 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 first two events are removed using the removeBatch() method.

Here removeEventsSuccess() and errorCallback() are two callback methods to show success and error message.

// Define the event success callback.
function onEventSearchSuccess(events) {
    //Delete the first two existing event.
    myCalendar.removeBatch([events[0].id, events[1].id], removeEventsSuccess, errorCallback);
    console.log("First two items deleted.");
}
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.