1

Can somebody tell me what is wrong here. I am trying to create a recurring appointment; however, the code creates something different (type is not Appointment) and, if I select one created element, it throws an error:

Falscher Datentyp für Operator oder @Funktion: Text erwartet

void Main()
{
    var session = new NotesSessionClass();
    session.Initialize("");
    var mailFile = session.GetEnvironmentString("MailFile", true);
    var server = session.GetEnvironmentString("MailServer", true);

    NotesDatabase database = session.GetDatabase("", mailFile, false);
    if(!database.IsOpen)
        database.Open();

    //Normal Meeting
    NotesDocument document = database.CreateDocument();

    UpdateAppointment(document, session);

    //Repeating Meeting
    DateTime appointmentStart = new DateTime(2020, 5, 13, 15, 0, 0);
    DateTime appointmentEnd = new DateTime(2020, 5, 13, 16, 0, 0);  

    List<DateTime> repeatStart = new List<DateTime>(){ appointmentStart, appointmentStart.AddDays(1), appointmentStart.AddDays(2), appointmentStart.AddDays(3) };
    List<DateTime> repeatEnd = new List<DateTime>(){ appointmentEnd, appointmentEnd.AddDays(1), appointmentEnd.AddDays(2), appointmentEnd.AddDays(3) };

    document.ReplaceItemValue("Repeats", 1);
    document.ReplaceItemValue("OrgRepeat", 1);
    document.ReplaceItemValue("$CSFlags", "i");

    NotesDocument repeatingMaster = database.CreateDocument();
    UpdateAppointment(repeatingMaster, session);
    repeatingMaster.ReplaceItemValue("Repeats", 1);
    repeatingMaster.ReplaceItemValue("OrgRepeat", 1);
    repeatingMaster.ReplaceItemValue("$CSFlags", "c");  

    repeatingMaster.ReplaceItemValue("RepeatStartDate", appointmentStart);
    repeatingMaster.ReplaceItemValue("RepeatHow", "F");
    repeatingMaster.ReplaceItemValue("RepeatFor", 4);
    repeatingMaster.ReplaceItemValue("RepeatForUnit", "D");

    repeatingMaster.ReplaceItemValue("RepeatUnit", "D");
    repeatingMaster.ReplaceItemValue("RepeatInterval", 1);

    repeatingMaster.ReplaceItemValue("RepeatDates", repeatStart.ToArray());
    repeatingMaster.ReplaceItemValue("RepeatInstanceDates", repeatStart.ToArray());
    repeatingMaster.ReplaceItemValue("RepeatEndDates", repeatEnd.ToArray());
    repeatingMaster.ReplaceItemValue("RepeatUntil", repeatEnd.Last());

    repeatingMaster.ReplaceItemValue("StartDateTime", repeatStart.First());
    repeatingMaster.ReplaceItemValue("EndDateTime", repeatEnd.First());
    repeatingMaster.ReplaceItemValue("StartTimeZone", "Z=-1$DO=1$DL=3 -1 1 10 -1 1$ZX=90$ZN=Romance");
    repeatingMaster.ReplaceItemValue("EndTimeZone", "Z=-1$DO=1$DL=3 -1 1 10 -1 1$ZX=90$ZN=Romance");
    repeatingMaster.ReplaceItemValue("ApptUNID", repeatingMaster.UniversalID);

    repeatingMaster.ComputeWithForm(false, false);
    repeatingMaster.Save(true, false);

    document.ReplaceItemValue("CalendarDateTime", repeatStart.ToArray());
    document.ReplaceItemValue("StartDateTime", repeatStart.ToArray());
    document.ReplaceItemValue("EndDateTime", repeatEnd.ToArray());
    document.ReplaceItemValue("RepeatInstanceDates", repeatStart.ToArray());
    document.ReplaceItemValue("StartTimeZone", "Z=-1$DO=1$DL=3 -1 1 10 -1 1$ZX=90$ZN=Romance");
    document.ReplaceItemValue("EndTimeZone", "Z=-1$DO=1$DL=3 -1 1 10 -1 1$ZX=90$ZN=Romance");

    document.ReplaceItemValue("$Ref", repeatingMaster.UniversalID);
    document.ReplaceItemValue("$RefOptions", 1);
    document.ReplaceItemValue("ApptUNID", repeatingMaster.UniversalID);

    document.ComputeWithForm(false, false);
    document.Save(true, false);

}

Method to update appointment document:

void UpdateAppointment(NotesDocument document, NotesSession session)
{
    document.ReplaceItemValue("Form", "Appointment");
    document.ReplaceItemValue("$CSVersion", 2);
    document.ReplaceItemValue("Subject", "Subject");
    document.ReplaceItemValue("Body", "Body");
    document.ReplaceItemValue("AppointmentType", 3);

    document.ReplaceItemValue("Chair", session.UserName);
    document.ReplaceItemValue("Principal", session.UserName);
    document.ReplaceItemValue("From", session.UserName);

    document.ReplaceItemValue("SequenceNum", 1);

    document.ReplaceItemValue("RequiredAttendees", "test@required.attendee");
    document.ReplaceItemValue("Location", "Location");
    document.ReplaceItemValue("$Alarm", 1);
    document.ReplaceItemValue("Alarms", 1);
    document.ReplaceItemValue("$AlarmOffset", -15);

    document.ReplaceItemValue("$BusyName", session.UserName);
    document.ReplaceItemValue("$BusyPriority", 1);

    document.ReplaceItemValue("$PublicAccess", 1);
    document.ReplaceItemValue("Importance", 1);

    document.ComputeWithForm(false, false);
    document.Save(true, false); 
}

I tried already all ways to find the error but I am a newbie in Lotus Notes and there is not enough documentation (or I can not find it).

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83

1 Answers1

2

Creating appointments in LotusScript is already not easy. But creating repeating appointments is very advanced stuff, as they are NOT single documents to create but always combinations of ONE main document and at least ONE response document.

To get this right you need to create a bunch of fields with the right data type and content.

In your example at least the Fields StartDate, StartTime, EndDate, EndTime and CalendarDate... are missing. your „Computewithform“ tries to calculate all missing fields from the used forms. But they need some fields and they need to be of the right type, otherwise you get @Formula- errors as the one you have (in your case it might be because you set Repeats as Number, but it should be a Text, but his was just the first wrong one that I saw in your code, there might and will be others)

There is a PDF document called Calendaring & Scheduling Schema that is quite old (2006) but still holds true: it describes how to programmatically create calendar entries and which fields you need and what they mean... read it, understand it, use it.

It’s the only way to get valid calendar entries without guessing or copying an existing document...

Tode
  • 11,795
  • 18
  • 34
  • Thank you Torsten, Have you perhaps information about how I can handle recurrence exceptions? – Viktoriusrex May 15 '20 at 05:27
  • Its all in that Schema... you need to create at least two responses: one with all instances before the exception and one with all instances after the exception... – Tode May 15 '20 at 05:52