Add()

Description:

The Add method creates a new calendar on the device or adds an entry to a calendar. In the latter case, if an entry with the same LocalId already exists in the calendar, it is modified accordingly. You can thus use this method to both add and update calendar entries. The entry is added to the specified calendar or, if no calendar is specified, to the default one. If the default calendar does not exist, it is created.

This is a synchronous method.

Syntax:

Add(parameters:Object):Object

Arguments:

Return value:

The Add method returns an object that contains an error code and an error message. In addition, if a calendar entry was added or updated, the result object contains the id of that entry.

Table: Return value properties for Add

Property

Description

Value

ReturnValue

This is a text string that contains the id of the entry that was added or updated.

If a new calendar was created, this property is not included in the result object.

 

ErrorCode

This is a number that specifies a predefined error code.

See Service API error codes.

ErrorString

This is a text string that describes the error.

Remarks:

  • If an entry is added or updated to a calendar other than the default one, the corresponding calendar file must exist on the device.

  • For detailed information about calendar entries, see section Calendar entries.

Example code:

The following sample code illustrates how to add a new calendar entry:

import com.nokia.lib.Service;
var calender = new Service("Service.Calendar", "IDataSource");
var toDo = {Type:"ToDo", EndTime:new Date(2008, 01, 14, 8, 50, 10, 0), Replication:"Open", Description:"Preapre expenses report", AlarmTime:new Date(2008, 01, 14, 9, 15, 10, 0), Priority:1, Status:"TodoNeedsAction"};
var inParams = {Type:"CalendarEntry", Item:toDo};
var outParams = calender.Add(inParams);
if (outParams.ErrorCode == 0) {
    var calenderId = outParams.ReturnValue;
} else {
    var errorId = outParams.ErrorCode;
}