Codeunit "Recurrence Schedule"
Calculates when the next event will occur. Events can recur daily, weekly, monthly or yearly.
Properties
| Name | Value |
|---|---|
| Access | Public |
| InherentEntitlements | X |
| InherentPermissions | X |
Methods
SetMinDateTime
Sets the earliest date to be returned from CalculateNextOccurrence. The default MinDateTime is today at the start time set in recurrence.
procedure SetMinDateTime(DateTime: DateTime)
Parameters
| Name | Type | Description |
|---|---|---|
| DateTime | DateTime |
The minimum datetime. |
Examples
To start calculating recurrence from January 1st, 2000, call SetMinDateTime(CREATEDATETIME(DMY2DATE(1, 1, 2000), 0T)).
CalculateNextOccurrence
Calculates the time and date for the next occurrence.
procedure CalculateNextOccurrence(RecurrenceID: Guid, LastOccurrence: DateTime): DateTime
Parameters
| Name | Type | Description |
|---|---|---|
| RecurrenceID | Guid |
The recurrence ID. |
| LastOccurrence | DateTime |
The time of the last scheduled occurrence. |
Returns
| Type | Description |
|---|---|
| DateTime |
Returns the DateTime value for the next occurrence. If there is no next occurrence, it returns the default value 0DT. |
Examples
To calculate the first occurrence (this is using the datatime provided in SetMinDateTime as a minimum datetime to return), call CalculateNextOccurrence(RecurrenceID, 0DT)), the RecurrenceID is the ID returned from one of the create functions.
CreateDaily
Creates a daily recurrence.
procedure CreateDaily(StartTime: Time, StartDate: Date, EndDate: Date, DaysBetween: Integer): Guid
Parameters
| Name | Type | Description |
|---|---|---|
| StartTime | Time |
The start time of the recurrence. |
| StartDate | Date |
The start date of the recurrence. |
| EndDate | Date |
The end date of the recurrence. |
| DaysBetween | Integer |
The number of days between each occurrence, starting with 1. |
Returns
| Type | Description |
|---|---|
| Guid |
The ID used to reference this recurrence. |
Examples
To create a recurrence that starts today, repeats every third day, and does not have an end date, call RecurrenceID := CreateDaily(now, today, 0D , 3).
CreateWeekly
Creates a weekly recurrence.
procedure CreateWeekly(StartTime: Time, StartDate: Date, EndDate: Date, WeeksBetween: Integer, Monday: Boolean, Tuesday: Boolean, Wednesday: Boolean, Thursday: Boolean, Friday: Boolean, Saturday: Boolean, Sunday: Boolean): Guid
Parameters
| Name | Type | Description |
|---|---|---|
| StartTime | Time |
The start time of the recurrence. |
| StartDate | Date |
The start date of the recurrence. |
| EndDate | Date |
The end date of the recurrence. |
| WeeksBetween | Integer |
The number of weeks between each occurrence, starting with 1. |
| Monday | Boolean |
Occur on Mondays. |
| Tuesday | Boolean |
Occur on Tuesdays. |
| Wednesday | Boolean |
Occur on Wednesdays. |
| Thursday | Boolean |
Occur on Thursdays. |
| Friday | Boolean |
Occur on Fridays. |
| Saturday | Boolean |
Occur on Saturdays. |
| Sunday | Boolean |
Occur on Sundays. |
Returns
| Type | Description |
|---|---|
| Guid |
The ID used to reference this recurrence. |
Examples
To create a weekly recurrence that starts today, repeats every Monday and Wednesday, and does not have an end date, call RecurrenceID := CreateWeekly(now, today, 0D , 1, true, false, true, false, false, false, false).
CreateMonthlyByDay
Creates a monthly recurrence by day.
procedure CreateMonthlyByDay(StartTime: Time, StartDate: Date, EndDate: Date, MonthsBetween: Integer, DayOfMonth: Integer): Guid
Parameters
| Name | Type | Description |
|---|---|---|
| StartTime | Time |
The start time of the recurrence. |
| StartDate | Date |
The start date of the recurrence. |
| EndDate | Date |
The end date of the recurrence. |
| MonthsBetween | Integer |
The number of months between each occurrence, starting with 1. |
| DayOfMonth | Integer |
The day of the month. |
Returns
| Type | Description |
|---|---|
| Guid |
The ID used to reference this recurrence. |
Examples
To create a monthly recurrence that repeats on the fourth day of every month, call RecurrenceID := CreateMonthlyByDay(now, today, 0D , 1, 4).
CreateMonthlyByDayOfWeek
Creates a monthly recurrence by the day of the week.
procedure CreateMonthlyByDayOfWeek(StartTime: Time, StartDate: Date, EndDate: Date, MonthsBetween: Integer, InWeek: Enum "Recurrence - Ordinal No.", DayOfWeek: Enum "Recurrence - Day of Week"): Guid
Parameters
| Name | Type | Description |
|---|---|---|
| StartTime | Time |
The start time of the recurrence. |
| StartDate | Date |
The start date of the recurrence. |
| EndDate | Date |
The end date of the recurrence. |
| MonthsBetween | Integer |
The number of months between each occurrence, starting with 1. |
| InWeek | Enum System.DateTime."Recurrence - Ordinal No." |
The week of the month. |
| DayOfWeek | Enum System.DateTime."Recurrence - Day of Week" |
The day of the week. |
Returns
| Type | Description |
|---|---|
| Guid |
The ID used to reference this recurrence. |
Examples
To create a monthly recurrence that calculates every last Friday of every month, call RecurrenceID := CreateMonthlyByDayOfWeek(now, today, 0D , 1, RecurrenceOrdinalNo::Last, RecurrenceDayofWeek::Friday).
CreateYearlyByDay
Creates a yearly recurrence by day.
procedure CreateYearlyByDay(StartTime: Time, StartDate: Date, EndDate: Date, YearsBetween: Integer, DayOfMonth: Integer, Month: Enum "Recurrence - Month"): Guid
Parameters
| Name | Type | Description |
|---|---|---|
| StartTime | Time |
The start time of the recurrence. |
| StartDate | Date |
The start date of the recurrence. |
| EndDate | Date |
The end date of the recurrence. |
| YearsBetween | Integer |
The number of years between each occurrence, starting with 1. |
| DayOfMonth | Integer |
The day of the month. |
| Month | Enum System.DateTime."Recurrence - Month" |
The month of the year. |
Returns
| Type | Description |
|---|---|
| Guid |
The ID used to reference this recurrence. |
Examples
To create a yearly recurrence that repeats on the first day of December, call RecurrenceID := CreateYearlyByDay(now, today, 0D , 1, 1, RecurrenceMonth::December).
CreateYearlyByDayOfWeek
Creates a yearly recurrence by day of week of a given month.
procedure CreateYearlyByDayOfWeek(StartTime: Time, StartDate: Date, EndDate: Date, YearsBetween: Integer, InWeek: Enum "Recurrence - Ordinal No.", DayOfWeek: Enum "Recurrence - Day of Week", Month: Enum "Recurrence - Month"): Guid
Parameters
| Name | Type | Description |
|---|---|---|
| StartTime | Time |
The start time of the recurrence. |
| StartDate | Date |
The start date of the recurrence. |
| EndDate | Date |
The end date of the recurrence. |
| YearsBetween | Integer |
The number of years between each occurrence, starting with 1. |
| InWeek | Enum System.DateTime."Recurrence - Ordinal No." |
The week of the month. |
| DayOfWeek | Enum System.DateTime."Recurrence - Day of Week" |
The day of the week. |
| Month | Enum System.DateTime."Recurrence - Month" |
The month of the year. |
Returns
| Type | Description |
|---|---|
| Guid |
The ID used to reference this recurrence. |
Examples
To create a yearly recurrence that repeats on the last Friday of every month, call RecurrenceID := CreateYearlyByDayOfWeek(now, today, 0D , 1, RecurrenceOrdinalNo::Last, RecurrenceDayofWeek::Weekday, RecurrenceMonth::December).
OpenRecurrenceSchedule
Opens the card for the recurrence.
procedure OpenRecurrenceSchedule(var RecurrenceID: Guid)
Parameters
| Name | Type | Description |
|---|---|---|
| RecurrenceID | Guid |
The recurrence ID. |
RecurrenceDisplayText
Returns a short text description of the recurrence.
procedure RecurrenceDisplayText(RecurrenceID: Guid): Text
Parameters
| Name | Type | Description |
|---|---|---|
| RecurrenceID | Guid |
The recurrence ID. |
Returns
| Type | Description |
|---|---|
| Text |
The short text to display. |