0

I have a calendar that employees use to request time away. When a user adds an item to the calendar, an e-mail is generated to the manager asking for approval/declination of the time away. What I cannot figure out is how to bring in all the information already on the calendar for the day. For instance, if I request tomorrow off, but Tom Stack has time already, the e-mail should appear as such:

Start Email

Coolest Person has requested time off for 08/06/2016.

Other individuals who have time off on 08/06/2016: Tom Stack - 4 hours from 8:00 AM to 12:00 PM

End Email

Does anyone have any ideas how this can be accomplished?

0

Create an ItemAdded event receiver for your calendar list.

public override void ItemAdded(SPItemEventProperties properties)

In the event receiver, read the properties of the entry created. You need the date of the event as well:

DateTime eventDate = DateTime.Parse(properties.ListItem["EventDate"]"].ToString(), null, DateTimeStyles.AdjustToUniversal);

Using this eventDate create and run a CAML query (using DateRangesOverlap, Today and CalendarDate, see example from here) to get all of the items for the same day:

<Where>
          <DateRangesOverlap>
               <FieldRef Name='EventDate'>
               <FieldRef Name='EndDate'>
               <FieldRef Name='RecurrenceID'>
               <Value Type='DateTime'>
                    <Today/>
               </Value>
          </DateRangesOverlap>
     </Where>

and

query.CalendarDate = {target date};

Build the message text based on the info you have, and send the mail.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.