none
Code sample for recurring meeting with different rooms RRS feed

  • Question

  • Hi,

    Can anyone provide a small vsto plugin code sample of the following scenario to create a recurring meeting which uses different rooms on different days:

    • New Meeting (recurring, daily for 3 days from 1pm-1:30pm (lets say mon/tues/wed)
    • Monday - use "Room1"
    • Tues - use "Room2"
    • Wed - use "Room3"

    Assuming this would populate the active "AppointmentItem" object which is created when clicking on "New Meeting" ribbon button to create a new meeting.

    thanks,

    Paul

    Monday, January 30, 2017 11:59 PM

Answers

  • If the server performs the check only on the conference room of the master appointment, you really have no choice but to create separate appointments for each room.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!


    Friday, February 3, 2017 11:15 PM

All replies

  • You cannot of that for the whole series - the best you can do is create exceptions for some particular days. Or create 3 separate recurring appointment series.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Tuesday, January 31, 2017 5:56 PM
  • Thanks for your reply Dmitry, i didnt want to go down the path of creating 3 separate meetings.

    Further to my data setup scenario, i would set the appoinment meeting room to be say Room1, then for the 2nd and 3rd days those 2 would then be exceptions. Do you have a code sample of how to create exceptions for a new AppointmentItem meeting object?


    • Edited by Milsnips Tuesday, January 31, 2017 10:49 PM
    Tuesday, January 31, 2017 10:05 PM
  • Call ApppointmentItem.GetRecurrencePattern, retrieve the instance using RecurrencePattern.GetOccurence, modify the returned ApppointmentItem object (representing a particular occurrence) to remove one recipient and add another one.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Tuesday, January 31, 2017 11:08 PM
  • tried this, the behaviour doesnt work as expected. 

    In psuedocode this is what i do:

    • Create new meeting, set recurring info (dont save yet)
    • Dont set any room on the meeting level. this will be done later
    • check for valid available rooms for the given recurring pattern.
    • execute VSTO plugin code (see below). in my testing scenario i set the most frequently available room as the primary room (lets say its Room1). then the rest of the alternative rooms are set for each relevant recurring instance (in each recurring instance i set to a different room, i also room the primary room from it.:

    here is my code sample i used.

    Inspector inspector = null;
    object item = null;
    AppointmentItem appointment = null;
    try
    {
        inspector = Globals.ThisAddIn.Application.ActiveInspector();
        if (inspector != null)
        {
            item = inspector.CurrentItem;
            if (item is AppointmentItem)
            {
                // use appointment 
                appointment = item as AppointmentItem;
                if (appointment.IsRecurring)
                {
                    //get the recurring item from appointment
                    var recurrencePattern = appointment.GetRecurrencePattern();
    
                    //find the primary room to use
                    var groupedRooms = _selectedScenario.Items.GroupBy(g => g.Address).Select(s => new { Address = s, Count = s.Count() }).ToList();
                    var primaryRoom = groupedRooms.OrderByDescending(x => x.Count).Select(s => s.Address).First().Key;
                    var singleRoomForAllDates = groupedRooms.Count() == 1;
    
                    //SET THE RECURRENCE INFO HERE...
                    SetPrimaryRoomResource(appointment, primaryRoom);
    
                    if (!singleRoomForAllDates)
                    {
                        //loop through the allocated rooms in the schedule and update the appointment accordingly
                        foreach (var scheduleEntry in _selectedScenario.Items.Where(x => x.Address.Address != primaryRoom.Address))
                        {
                            //get the recurring item occurence for the entry start date
                            var occurenceInstance = recurrencePattern.GetOccurrence(scheduleEntry.Range.Start);
                            if (occurenceInstance != null)
                            {
                                //remove the primary address in this instance
                                int index = 0;
                                bool found = false;
                                Recipient rec = null;
                                Recipients recs = occurenceInstance.Recipients as Recipients;
                                for (int i = 1; i < occurenceInstance.Recipients.Count + 1; i++)
                                {
                                    index = i;
                                    rec = recs[i] as Recipient;
                                    if (!rec.Name.Equals(primaryRoom.Name)) continue;
                                    found = true;
                                    break;
                                }
    
                                if (found) { occurenceInstance.Recipients.Remove(index); }
                                ReleaseComObject(rec);
                                ReleaseComObject(recs);
    
    
                                //replace the occurance instance location with the different room resource.
                                occurenceInstance.Subject = $"{appointment.Subject} - Room Change to {scheduleEntry.Address.Name}";
                                occurenceInstance.Location = scheduleEntry.Address.Name;
                                var rcpt = occurenceInstance.Recipients.Add(scheduleEntry.Address.Name);
                                rcpt.Type = (int)OlMeetingRecipientType.olResource;
    
                                occurenceInstance.Save();
    
                                ///also msdn link example which doesnt behave as mentioned, when trying to set exception against a newly created appointment (not yet saved/sent)
                                /// https://msdn.microsoft.com/en-us/library/office/ff184635.aspx
                            }
    
                        }
                    }
                }
            }
        }
    }
    catch (Exception exception)
    {
        Console.WriteLine(exception);
        throw;
    }
    finally
    {
        ReleaseComObject(item);
        ReleaseComObject(appointment);
        ReleaseComObject(inspector);
    }

    The microsoft link in my code points to a code sample which says to save the appointment after changing a recurring instance, then reloading the recurringPattern and reading the exception, but when i do that, the exception object has no entries.

    Once all the objects are set and i click send, whatever instances i set with alternative rooms come back as a conflict in the declined email because it seems to check it against the primary room only.


    • Edited by Milsnips Thursday, February 2, 2017 3:24 AM
    Thursday, February 2, 2017 3:22 AM
  • If the server performs the check only on the conference room of the master appointment, you really have no choice but to create separate appointments for each room.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!


    Friday, February 3, 2017 11:15 PM
  • Yeah thats what i'm unsure of but i suspect might be happening.
    Sunday, February 5, 2017 10:19 PM