Office365Calendar is the Microsoft Graph API client for calendar and event management within 4D NetKit. It supports reading, creating, updating, and deleting calendars and events, with optional calendarId and userId scoping.
An Office365Calendar object is accessed via the calendar property of an Office365 object: $office365.calendar.
Event date/time values are accepted as ISO text, {date; time} objects, or Graph {dateTime; timeZone} objects.
An Office365Calendar object exposes the following properties:
| Property | Type | Description |
|---|---|---|
| userId | Text | User identifier used in Service mode. Can be the id or the userPrincipalName. |
| id | Text | Calendar identifier. When set, all operations target this specific calendar by default. |
.getCalendar( { id : Text } ) : Object
| Parameter | Type | Description | |
|---|---|---|---|
| id | Text | -> | ID of the calendar to retrieve. To retrieve calendar IDs, call .getCalendars(). If id is null, empty, or missing, returns the primary calendar of the currently logged-in user. |
| Result | Object | <- | Object containing the properties and relationships of the specified calendar, or Null on failure. |
.getCalendar() retrieves the properties and relationships of a specific calendar.
var $oAuth2 : cs.NetKit.OAuth2Provider
var $Office365 : cs.NetKit.Office365
var $params; $calendarList; $calendarA : Object
$params:=New object
$params.name:="Microsoft"
$params.permission:="signedIn"
$params.clientId:="your-client-id"
$params.redirectURI:="http://127.0.0.1:50993/authorize/"
$params.scope:="https://graph.microsoft.com/.default"
$oAuth2:=New OAuth2 provider($params)
$Office365:=New Office365 provider($oAuth2)
// Retrieve the entire list of calendars
$calendarList:=$Office365.calendar.getCalendars()
// Retrieve the first calendar in the list using its ID
$calendarA:=$Office365.calendar.getCalendar($calendarList.calendars[0].id)
.getCalendars( { param : Object } ) : cs.NetKit.GraphCalendarList
| Parameter | Type | Description | |
|---|---|---|---|
| param | Object | -> | Set of options to filter, order, or select specific calendar properties (optional). |
| Result | cs.NetKit.GraphCalendarList | <- | Paginated list of calendar objects. Use next() / previous() to navigate pages. |
.getCalendars() retrieves a collection of the user’s calendars.
In param, you can pass the following optional properties:
| Property | Type | Description |
|---|---|---|
| select | Text | Specifies which calendar properties to retrieve. Comma-separated values. |
| orderby | Text | Specifies the order of the returned results. Syntax: property name followed by asc or desc. |
| filter | Text | OData filter expression to filter the results. Example: "name eq 'Work'". |
var $oAuth2 : cs.NetKit.OAuth2Provider
var $Office365 : cs.NetKit.Office365
var $params; $calendarList : Object
$params:=New object
$params.name:="Microsoft"
$params.permission:="signedIn"
$params.clientId:="your-client-id"
$params.redirectURI:="http://127.0.0.1:50993/authorize/"
$params.scope:="https://graph.microsoft.com/.default"
$oAuth2:=New OAuth2 provider($params)
$Office365:=New Office365 provider($oAuth2)
$calendarList:=$Office365.calendar.getCalendars()
.createEvent( event : Object ) : Object
| Parameter | Type | Description | |
|---|---|---|---|
| event | Object | -> | Object containing the details of the calendar event to create. |
| Result | Object | <- | Status object with an additional event property. |
.createEvent() creates a new calendar event.
In event, pass the properties you want to set. See GraphEvent for the full list of available properties. Attachments in event.attachments are uploaded separately after event creation.
The method returns a status object with an additional event property:
| Property | Type | Description |
|---|---|---|
| event | Object | GraphEvent returned by the server. |
| success | Boolean | See status object. |
| statusText | Text | See status object. |
| errors | Collection | See status object. |
| Type | Permission |
|---|---|
| Delegated (Work/School) | Calendars.ReadWrite |
| Delegated (Personal) | Calendars.ReadWrite |
| Application | Calendars.ReadWrite |
var $oAuth2 : cs.NetKit.OAuth2Provider
var $Office365 : cs.NetKit.Office365
var $event; $result : Object
$Office365:=New Office365 provider($oAuth2)
$event:={}
$event.subject:="Team Sync"
$event.start:={date: Current date; time: Current time}
$event.end:={date: Current date; time: Current time+3600}
$event.attendees:=[{emailAddress: {address: "colleague@example.com"}}]
$result:=$Office365.calendar.createEvent($event)
If (Not($result.success))
ALERT($result.statusText)
End if
.deleteEvent( param : Object ) : Object
| Parameter | Type | Description | |
|---|---|---|---|
| param | Object | -> | Object containing details for the calendar event to delete. |
| Result | Object | <- | Status object. |
.deleteEvent() deletes a calendar event.
In param, you can pass the following properties:
| Property | Type | Description |
|---|---|---|
| eventId | Text | Required. ID of the event to delete. |
| calendarId | Text | ID of the calendar. If not provided, the primary calendar of the currently logged-in user is used. |
The method returns a standard status object.
| Type | Permission |
|---|---|
| Delegated (Work/School) | Calendars.ReadWrite |
| Delegated (Personal) | Calendars.ReadWrite |
| Application | Calendars.ReadWrite |
$status:=$office365.calendar.deleteEvent({eventId: $event.id})
If ($status.success)
ALERT("Calendar event correctly deleted")
Else
ALERT($status.statusText)
End if
.getEvent( param : Object ) : cs.NetKit.GraphEvent
| Parameter | Type | Description | |
|---|---|---|---|
| param | Object | -> | Object containing the necessary details to retrieve a specific event. |
| Result | cs.NetKit.GraphEvent | <- | The requested GraphEvent, or Null when not found or on error. |
.getEvent() retrieves details of a specific event, including its properties and relationships. The event is identified by its unique eventId within the specified calendar.
In param, you can pass the following properties:
| Property | Type | Description |
|---|---|---|
| eventId | Text | Required. The unique identifier of the event. |
| calendarId | Text | Calendar identifier. If not provided, the user’s primary calendar is used. |
| timeZone | Text | Time zone for the response (IANA format). UTC by default. |
| select | Text | OData $select — comma-separated list of properties to return. |
.getEvents( { param : Object } ) : cs.NetKit.GraphEventList
| Parameter | Type | Description | |
|---|---|---|---|
| param | Object | -> | Object containing filters and options for retrieving calendar events (optional). |
| Result | cs.NetKit.GraphEventList | <- | Paginated list of GraphEvent instances. Use next() / previous() to navigate pages. |
.getEvents() retrieves events from a specified calendar. By default, events are pulled from the user’s primary calendar unless another calendar is specified.
Note: If no time range is provided, it returns single-instance meetings and series masters. When both startDateTime and endDateTime are specified, it retrieves all occurrences, exceptions, and single-instance events within the defined time range.
In param, you can pass the following optional properties:
| Property | Type | Description |
|---|---|---|
| calendarId | Text | Calendar identifier. If not provided, the user’s primary calendar is used. |
| startDateTime | Text, Object | Filters events by start time. If set, endDateTime must also be provided. Text: ISO 8601 UTC timestamp. Object: Must contain date (date type) and time (time type). |
| endDateTime | Text, Object | Filters events by end time. If set, startDateTime must also be provided. |
| timeZone | Text | Time zone for the response (IANA format). UTC by default. |
| select | Text | Specifies which event properties to return (OData $select). |
| orderby | Text | Defines sorting order for results (OData $orderby). |
| filter | Text | OData filter expression. Example: "status eq 'confirmed'". |
| top | Integer | Maximum number of events per page. Default is 10. Maximum is 999. |
// Get all calendars, then retrieve events from the first one
var $calendars:=$office365.calendar.getCalendars()
var $myCalendar:=$calendars.calendars[0]
var $events:=$office365.calendar.getEvents({calendarId: $myCalendar.id; top: 10})
.updateEvent( event : Object ) : Object
| Parameter | Type | Description | |
|---|---|---|---|
| event | Object | -> | Object containing the updated event properties. The id property is mandatory. |
| Result | Object | <- | Status object with an additional event property. |
.updateEvent() updates an existing calendar event.
In event, pass the event id (mandatory) and the properties you want to update. You only need to include the fields you want to change — any property left out will keep its current value. Attachments in event.attachments are uploaded separately after the update.
The method returns a status object with an additional event property:
| Property | Type | Description |
|---|---|---|
| event | Object | Updated GraphEvent returned by the server. |
| success | Boolean | See status object. |
| statusText | Text | See status object. |
| errors | Collection | See status object. |
| Type | Permission |
|---|---|
| Delegated (Work/School) | Calendars.ReadWrite |
| Delegated (Personal) | Calendars.ReadWrite |
| Application | Calendars.ReadWrite |
#DECLARE($eventId : Text)
var $Office365:=New Office365 provider($oAuth2)
var $event; $result : Object
$event:={}
$event.id:=$eventId
$event.subject:="Updated Meeting Title"
$event.start:={date: Current date; time: Current time}
$event.end:={date: Current date; time: Current time+3600}
$result:=$Office365.calendar.updateEvent($event)
If (Not($result.success))
ALERT($result.statusText)
End if
.notifier( param : Object { ; calendarId : Text } ) : cs.NetKit.GraphNotification
| Parameter | Type | Description | |
|---|---|---|---|
| param | Object | -> | Callback and mode definitions (see below). |
| calendarId | Text | -> | (optional) Subscribe to changes in that specific calendar. If omitted, subscribe to the default calendar. |
| Result | cs.NetKit.GraphNotification | <- | Notification object with start(), stop(), expiration, and isStarted. Call start() to begin monitoring. |
.notifier() creates and returns a GraphNotification object allowing you to configure, start, and stop subscriptions to calendar event change notifications.
Two modes are available:
{endPoint}/4dnk-graph-notification?state={uuid}.When a resource changes, user-defined callbacks are dispatched in the 4D worker where the notifier’s start() function was originally called.
In param, you can pass the following properties:
| Property | Type | Description |
|---|---|---|
| endPoint | Text | Webhook URL for push mode. If omitted, uses pull mode. Must be a publicly accessible HTTPS endpoint. See endPoint management. |
| onCreate | 4D.Function | Callback for a calendar event creation (optional). |
| onDelete | 4D.Function | Callback for a calendar event deletion (optional). |
| onModify | 4D.Function | Callback for a calendar event modification (optional). |
| timer | Integer | Polling interval in seconds for pull mode (default: 30) (optional). |
Callback functions receive two parameters:
| Parameter | Type | Description |
|---|---|---|
| office365 | cs.NetKit.Office365 | The current Office365 object. |
| event | Object | Object with type (Text: "eventCreated", "eventDeleted", or "eventModified") and ids (Collection of affected event IDs). |
The returned GraphNotification object contains the following properties:
| Property | Type | Description |
|---|---|---|
| endPoint | Text | Publicly accessible HTTPS endpoint that receives notifications. |
| expiration | Text | Expiration date and time (timestamp). Read-only. |
| isStarted | Boolean | true when notifications are active, false when stopped. Read-only. |
| start() | 4D.Function | Starts the subscription. Returns a status object (success, statusText, errors). |
| stop() | 4D.Function | Stops the subscription. Returns a status object (success, statusText, errors). |
| timer | Integer | Interval in seconds between delta query checks (pull mode). |
endPoint managementUsing an endPoint, you let Microsoft call your application whenever a change occurs:
$parameter.endPoint:="https://mydomain.com/notifications"
endPoint port is the same as the host port, the host web server is used automatically.When the endPoint uses the host web server, add the following entry to Project/Sources/HTTPHandlers.json:
[
{
"class": "NetKit.GraphNotificationHandler",
"method": "getResponse",
"regexPattern": "/4dnk-graph-notification",
"verbs": "post"
}
]
If both a
calendar.notifierand amail.notifierare declared, they must use the same port.
Calendar notifications via delta polling every 60 seconds (pull mode):
$calNotif:=$office365.calendar.notifier({ \
timer: 60; \
onCreate: Formula(handleNewEvent($1; $2)); \
onModify: Formula(handleEventUpdate($1; $2)) \
})
$status:=$calNotif.start()
// Stop monitoring
$status:=$calNotif.stop()
Several Office365Calendar functions return a status object containing the following properties:
| Property | Type | Description |
|---|---|---|
| success | Boolean | true if the operation was successful. |
| statusText | Text | Status message returned by the Microsoft server or last error from the 4D error stack. |
| errors | Collection | Collection of 4D error items (not returned if a server response is received): errcode, message, componentSignature. |