Thursday, July 7, 2011

CRM 2011 Holiday Retrieval


Holidays in CRM are stored in the CalendarRules entity but unfortunately Retrieve and RetrieveMultiple messages are not supported for this entity.  Below is a snippet of code that will help to find the CalendarId that contains the holidays and how to retrieve the individual holidays themselves.

           var org = (from o in Context.OrganizationSet
                          select o).FirstOrDefault();

            var businessClosureCalendarId = org.BusinessClosureCalendarId.Value;
            var businessClosureCalendar = (from c in Context.CalendarSet
                                           where c.CalendarId == businessClosureCalendarId
                                           select c).FirstOrDefault();

            var calendarRules = businessClosureCalendar.CalendarRules;

Enjoy!

4 comments:

  1. Glad to see you blogging again :)

    ReplyDelete
  2. Hi Blake!
    How you can validate if a input date is between business Closure?

    ReplyDelete
  3. Silvia,

    The ExpandCalendarRequest might be what you are looking for. http://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.expandcalendarrequest_members.aspx

    ReplyDelete
    Replies
    1. Might give an example, do an example and sends me an error of invalid time zone code

      Delete