Alfresco - Calendar event using server-side javascript

122 Views Asked by At

How to create calendar event using server-side javascript code?

1

There are 1 best solutions below

0
On

Here is the code for creating calendar event.

var node = companyhome.childByNamePath("Sites/demo/calendar"); 
var myEvent = node.createNode(new Date().getTime() + "-" + Math.round(Math.random()*10000) + ".ics", "ia:calendarEvent")
myEvent.properties["ia:whereEvent"] = "Where event";
myEvent.properties["ia:descriptionEvent"] = "This is the description";
myEvent.properties["ia:whatEvent"] = "What event";


var fromDate = new Date();
var fromISODate = utils.toISO8601(fromDate);
myEvent.properties["ia:fromDate"] = fromISODate;

var toDate = new Date();
toDate.setHours(toDate.getHours() + 3);
var toISODate = utils.toISO8601(toDate);
myEvent.properties["ia:toDate"] = toISODate;


myEvent.save();
logger.warn("Created new calendar event: " + myEvent.nodeRef);