I am trying to use the Aspose.Email Java edition to create a monthly recurrence pattern that repeats every Nth weekday of the month. For example, say the event occurs on the 3rd Wednesday of the month, for 6 occurrences. I want to create a MapiCalendarMonthlyRecurrencePattern which expresses that.
Through some searching it seems I have to call .setPosition()
and .setDayOfWeek()
on the MapiCalendarMonthlyRecurrencePattern
object. But when I do that, I get this error:
AsposeException: BYSETPOS must only be used in conjunction with another BYxxx rule part.
java.lang.StackTraceElement;
at com.aspose.email.RecurrenceRule.a(SourceFile:418)
at com.aspose.email.CalendarRecurrence.a(SourceFile:585)
at com.aspose.email.CalendarRecurrence.b(SourceFile:352)
at com.aspose.email.CalendarRecurrence.a(SourceFile:274)
at com.aspose.email.MapiCalendarRecurrencePatternFactory.a(SourceFile:468)
Here is a snippet that illustrates this:
Calendar jcalendar = Calendar.getInstance(java.util.TimeZone.getDefault());
jcalendar.set(2021, java.util.Calendar.MARCH, 17, 15, 30, 0);
Date startDate = jcalendar.getTime();
jcalendar.set(2021, java.util.Calendar.MARCH, 17, 16, 0, 0);
Date endDate = jcalendar.getTime();
MapiCalendar event = new MapiCalendar("location", "summary", "description", startDate, endDate);
MapiCalendarMonthlyRecurrencePattern pattern = new MapiCalendarMonthlyRecurrencePattern();
pattern.setPatternType(MapiCalendarRecurrencePatternType.Month);
pattern.setPeriod(1);
pattern.setWeekStartDay(DayOfWeek.Sunday);
pattern.setStartDate(startDate);
pattern.setEndType(MapiCalendarRecurrenceEndType.EndAfterNOccurrences);
pattern.setOccurrenceCount(6);
pattern.setPosition(3);
pattern.setDayOfWeek(DayOfWeek.Wednesday);
MapiCalendarEventRecurrence r = new MapiCalendarEventRecurrence();
r.setAppointmentTimeZoneDefinitionRecur(new MapiCalendarTimeZone("UTC"));
r.setTimeZoneStruct(new MapiCalendarTimeZone("UTC"));
r.setRecurrencePattern(pattern);
r.setClipStart(startDate);
event.setRecurrence(r);
event.setStartDateTimeZone(new MapiCalendarTimeZone("UTC"));
event.setEndDateTimeZone(new MapiCalendarTimeZone("UTC"));
// writing the PST happens elsewhere in our code, the rest is copied from another forum post.
PersonalStorage pst = PersonalStorage.create("DailyPst.pst", FileFormatVersion.Unicode);
FolderInfo fi = pst.createPredefinedFolder("CalPst", StandardIpmFolder.Appointments);
fi.addMapiMessageItem(event);
Is there something that must be changed to make this work?
Thanks for your help.