Sometimes you need to create and update a recurring appointment, such as a weekly status meeting for a team project or a yearly birthday reminder. Use the Office JavaScript API to manage the recurrence patterns of an appointment series in your add-in.
The recurrence pattern of an appointment is made up of a recurrence type (such as daily or weekly recurrence) and its applicable recurrence properties (for example, the day of the month the appointment occurs).
The following table lists the available recurrence types, their configurable properties, and descriptions of their usage.
An appointment occurs on day dayOfMonth of month every interval years. For example, an appointment occurs on the seventh day of September every four years.
An appointment occurs on the weekNumberdayOfWeek of month every interval years. For example, an appointment occurs on the firstThursday of September every two years.
Съвет
You can also use the firstDayOfWeek property with the weekly recurrence type. The specified day will start the list of days displayed in the recurrence dialog.
Access the recurrence pattern
As shown in the following table, how you access the recurrence pattern and what you can do with it depends on:
Whether you're the appointment organizer or an attendee.
Whether you're using the add-in in compose or read mode.
Whether the current appointment is a single occurrence or a series.
Along with the recurrence pattern, you also need to determine the start and end dates and times of your appointment series. The SeriesTime object is used to manage that information.
The appointment organizer can specify the recurrence pattern for an appointment series in compose mode only. In the following example, the appointment series is set to occur from 10:30 AM to 11:00 AM PST every Tuesday and Thursday during the period November 2, 2019 to December 2, 2019.
In the following example, the appointment organizer gets the Recurrence object of an appointment series, then sets a new recurrence duration. This is done in compose mode.
JavaScript
Office.context.mailbox.item.recurrence.getAsync((asyncResult) => {
const recurrencePattern = asyncResult.value;
recurrencePattern.seriesTime.setDuration(60);
Office.context.mailbox.item.recurrence.setAsync(recurrencePattern, (asyncResult) => {
if (asyncResult.status === Office.AsyncResultStatus.Failed) {
console.log("Failed to set recurrence.");
return;
}
console.log("Successfully set recurrence.");
});
});
Get recurrence as the organizer
In the following example, the appointment organizer gets the Recurrence object of an appointment to determine whether it's a recurring series. This is done in compose mode.
The following example shows the results of the getAsync call that retrieves the recurrence of a series.
Бележка
In this example, seriesTimeObject is a placeholder for the JSON representing the recurrence.seriesTime property. You should use the SeriesTime methods to get the recurrence date and time properties.
The following example shows the value of the item.recurrence property of an appointment series.
Бележка
In this example, seriesTimeObject is a placeholder for the JSON representing the recurrence.seriesTime property. You should use the SeriesTime methods to get the recurrence date and time properties.
After you've retrieved the recurrence object (either from the getAsync callback or from item.recurrence), you can get specific properties of the recurrence. For example, get the start and end dates and times of the series by using the SeriesTime methods on the recurrence.seriesTime property.
JavaScript
// Get series date and time infoconst seriesTime = recurrence.seriesTime;
const startTime = recurrence.seriesTime.getStartTime();
const endTime = recurrence.seriesTime.getEndTime();
const startDate = recurrence.seriesTime.getStartDate();
const endDate = recurrence.seriesTime.getEndDate();
const duration = recurrence.seriesTime.getDuration();
// Get series time zoneconst timeZone = recurrence.recurrenceTimeZone;
// Get recurrence propertiesconst recurrenceProperties = recurrence.recurrenceProperties;
// Get recurrence typeconst recurrenceType = recurrence.recurrenceType;
Run sample snippets in Script Lab
To test how to get and set the recurrence of an appointment with an add-in, install the Script Lab for Outlook add-in and run the following sample snippets.
Източникът за това съдържание може да бъде намерен в GitHub, където можете също да създавате и преглеждате проблеми и да изтегляте искания. За повече информация вижте нашето ръководство за сътрудник.
Обратна връзка за Office Add-ins
Office Add-ins е проект с отворен код. Изберете връзка, за да предоставите обратна връзка: