Is there a way to create a calendar event using javascript?
I have a folder rule to execute a javascript that I would like to create an event in the site's calendar.
I am using code that is similar to what I used to create datalist items and it seems to create the item but the item does not look right when I compare it to an item that I create through the UI
I use the childByNamePath() to get the site Calendar "siteCalendar". The item gets created but the primary path ends with something like this "cm:_x0037_3b5d28b-48ad-45e3-8f5c-a2c6eb0405df" rather than an ics name like "1594842338500-5440ics"
var myEvent = siteCalendar.createNode(null, "ia:calendarEvent") myEvent.properties["ia:whereEvent"] = "Where event"; myEvent.properties["ia:descriptionEvent"] = "This is the description"; var fromDate = new Date(); var fromISODate = utils.toISO8601(fromDate); myEvent.properties["ia:fromDate"] = fromISODate; var toDate = new Date(); toDate.setHours(toDate.getHours() + 1); var toISODate = utils.toISO8601(toDate); myEvent.properties["ia:toDate"] = toISODate; myEvent.properties["ia:whatEvent"] = "What event"; myEvent.save(); logger.warn("Created new calendar event: " + myEvent.nodeRef);
Used your code with small change and its working.
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);
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.