Working with calendar events is a core part of many business applications. Whether you’re organizing a team meeting or managing an event’s life cycle, being able to create, update, and delete events programmatically is essential.
In this blog post, we’ll walk through how to perform these operations using the Office365.calendar or Google.calendar classes provided in 4D 20 R10, powered by the Microsoft Graph and Google Calendar APIs.
HDI Calendar Events Management
Let’s explore how simple it is to create, update, and delete a meeting in Microsoft or Google Calendar using 4D NetKit, with the example below.
Account connection
As usual, before using Google or Microsoft APIs, we will create an OAuth 2.0 connection object:
For Google API:
var $oAuth2:=cs.NetKit.OAuth2Provider.new($googleCredentials)
var $google:=cs.NetKit.Google.new($oAuth2)
For Microsoft API:
var $oAuth2:=cs.NetKit.OAuth2Provider.new($microsoftCredentials)
var $office365:=cs.NetKit.Office365.new($oAuth2)
Create an Event
The calendar.createEvent() function allows you to create a new event in a calendar, either in the default calendar of the current user or a specified calendar.
for Google API:
var $myEvent:={start: {}; end: {}}
// Create a one-hour meeting
$myEvent.start.date:=Current date
$myEvent.start.time:=Current time
$myEvent.end.date:=Current date
$myEvent.end.time:=Current time+3600
$myEvent.summary:="My event"
$myEvent.description:="This is an invitation"
$myEvent.attendees:=[{email: "myAttendeeAddress@mail.com"}]
// Meeting creation
$event:=$google.calendar.createEvent($myEvent)
for MICROSOFT API:
var $myEvent:={start: {}; end: {}}
// Create a one-hour meeting
$myEvent.start.date:=Current date
$myEvent.start.time:=Current time
$myEvent.end.date:=Current date
$myEvent.end.time:=Current time+3600
$myEvent.isAllDay:=False
$myEvent.attendees:=[{emailAddress: {address: "myAttendeeAddress@mail.com"}; type: "required"}]
$myEvent.subject:="My event"
$myEvent.body:={content: "This is an invitation body"; contentType: "text"}
// Meeting creation
$event:=$office365.calendar.createEvent($myEvent)
Update an Event
The calendar.updateEvent() function lets you modify an existing event. You only need to provide the properties you want to update — existing ones not included remain unchanged.
for Google API:
var $myUpdateEvent:={}
$myUpdateEvent.summary:="My updated subject"
// Meeting update
$event:=$google.calendar.updateEvent($myUpdateEvent)
for MICROSOFT API:
var $myUpdateEvent:={}
$myUpdateEvent.subject:="My updated subject"
// Meeting update
$event:=$office365.calendar.updateEvent($myUpdateEvent)
Delete an Event
The calendar.deleteEvent() function removes an event from a calendar. If the event is a meeting, attendees are notified automatically with a cancellation message. Both commands take the same parameters:
for Google API:
$status:=$google.calendar.deleteEvent({eventId: $event.event.id})
for MICROSOFT API:
$status:=$office365.calendar.deleteEvent({eventId: $event.event.id})
Conclusion
By combining the createEvent, updateEvent, and deleteEvent functions from 4D NetKit, you can fully manage Microsoft 365 or Google calendar events directly from your 4D applications. Whether you’re building a meeting scheduler, a booking system, or a custom dashboard, this integration gives your users powerful tools to stay organized and connected.
