Work Hours in CRM

Posted On September 3, 2018 by Admin Posted in  Tagged in ,

In this article, we will learn how we can leverage the work hours in Reporting.

The calendar entity stores data for customer service calendars and holiday schedules in addition to business. Each calendar is set for a specific time zone.

A calendar describes the availability of a service or a resource. Calendars are related to calendarrule records, which include details about the duration, start and end times, and recurring patterns of events included in the calendar.

There are two types of calendar rules in Microsoft Dynamics 365:

  • Root: A calendar rule that contains an inner calendar or that has nested (leaf) rules. You can specify an inner calendar for a root calendar rule by using the InnerCalendarId attribute. The attribute value of CalendarRule.InnerCalendarId of a root rule is the same as the attribute value of CalendarRule.CalendarId of its leaf rules.
  • Leaf: A calendar rule that doesn’t contain an inner calendar, and therefore, is the end of the “branch.”

Referred from Blog: https://msdn.microsoft.com/en-us/library/gg328538.aspx

To obtain Work Hours of a resource, you can use the following fetchxml code:

<fetch version="1.0" output-format="xml-platform" mapping="logical" >

  <entity name="bookableresource">   <!-- You can use systemuser to retrieve same data -->

        <link-entity name="calendar" from="calendarid" to="calendarid" alias="c" >

            <link-entity name="calendarrule" from="calendarid" to="calendarid" alias="cr" >

                <attribute name="starttime" />

                <attribute name="effectiveintervalend" />

                <filter type="or" >
<!-- These filters are applied to get calendar of this year only -->

                    <condition attribute="starttime" operator="this-year" />

                    <condition attribute="effectiveintervalend" operator="this-year" />

                    <condition attribute="effectiveintervalend" operator="ge" value="12/30/9999" />

<!-- 12/30/9999 is the max end date i.e infinite time -->

                </filter>
                <link-entity name="calendar" from="calendarid" to="innercalendarid" alias="inc" >

                    <link-entity name="calendarrule" from="calendarid" to="calendarid" alias="incr" >

                        <attribute name="duration" />

                        <filter>

                            <condition attribute="duration" operator="lt" value="1440" />

<!-- 1440 minutes equals 24 hours which is redundant. As the calendar includes Business Closures and holidays we want to avoid such calendar records  -->

                        </filter>

                    </link-entity>

                </link-entity>

            </link-entity>

        </link-entity>

</fetch>

Share Story :