{"id":815,"date":"2014-08-06T13:05:14","date_gmt":"2014-08-06T07:35:14","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=815"},"modified":"2014-08-06T13:05:14","modified_gmt":"2014-08-06T07:35:14","slug":"calendars-and-expand-calendar-request-in-crm-2013-sp-1","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2014\/08\/calendars-and-expand-calendar-request-in-crm-2013-sp-1\/","title":{"rendered":"Calendars and Expand Calendar request in CRM 2013 SP 1"},"content":{"rendered":"<p style=\"text-align: justify;\">In this blog, we have explained how CRM stores the records for calendar, and how can we programmatically retrieve them from CRM.<\/p>\n<p style=\"text-align: justify;\">In CRM 2013 SP 1, two new calendar types are introduced. With that, we now have the following 4 types of calendars in CRM:<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\"67\">\n<p style=\"text-align: center;\"><strong>Type<\/strong><\/p>\n<\/td>\n<td style=\"text-align: center;\" width=\"174\"><strong>Name<\/strong><\/td>\n<td width=\"594\">\n<p style=\"text-align: center;\"><strong>Description<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"67\">\n<p style=\"text-align: center;\">0<\/p>\n<\/td>\n<td width=\"174\">\n<p style=\"text-align: center;\">Default<\/p>\n<\/td>\n<td width=\"594\">This type uses for business closure and work schedule\u2019s records of service scheduling.<\/td>\n<\/tr>\n<tr>\n<td width=\"67\">\n<p style=\"text-align: center;\">-1<\/p>\n<\/td>\n<td width=\"174\">\n<p style=\"text-align: center;\">Inner Calendar Type<\/p>\n<\/td>\n<td width=\"594\">Inner Calendars are used by other calendars to build a graph of time slots available for customer service or service scheduling to be performed.<\/td>\n<\/tr>\n<tr>\n<td width=\"67\">\n<p style=\"text-align: center;\">2<\/p>\n<\/td>\n<td width=\"174\">\n<p style=\"text-align: center;\">Holiday Schedule<\/p>\n<\/td>\n<td width=\"594\">This is also a new Type of calendar. And it uses for creating the Holiday Schedule records.<\/td>\n<\/tr>\n<tr>\n<td width=\"67\">\n<p style=\"text-align: center;\">1<\/p>\n<\/td>\n<td width=\"174\">\n<p style=\"text-align: center;\">Customer Service<\/p>\n<\/td>\n<td width=\"594\">This is new type of calendar. And it uses for creating the Customer Service Schedule records.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"text-align: justify;\">When we create the records for the weekly schedule for Facility\/Equipment and Users, Business Closure, Holiday Schedule and Customer Service Schedule in CRM, out of public view, CRM creates the records for them in the Calendar and Calendar Rule entity. Below, we have explained how the records are created in Calendar and Calendar Rule entities and how we can<strong><\/strong> retrieve them.<\/p>\n<p style=\"text-align: justify;\"><strong>Note: <\/strong><span style=\"text-decoration: underline;\">As we can\u2019t do the Advance find for the Calendar and Calendar Rule entity, we have displayed the records from the SQL database below. By\u00a0using the OrganizationService, you can programmatically retrieve the Calendar and Calendar Rule\u2019s records.<\/span><\/p>\n<p style=\"text-align: justify;\"><strong>1. <span style=\"text-decoration: underline;\">Default type for Business Closure<\/span><\/strong>: By default CRM have a record in the Calendar entity for Type O and Name \u201c<strong>Business Closure Calendar<\/strong>\u201d as shown in the below screenshot:<\/p>\n<p style=\"text-align: justify;\"><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2014\/08\/img11.jpg\"><img decoding=\"async\" class=\"alignnone size-full wp-image-816\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2014\/08\/img11.jpg\" alt=\"img1\" width=\"735\" height=\"129\" \/><\/a><\/p>\n<p style=\"text-align: justify;\">Now if we create the records of the Business Closure in CRM, it will create the record for \u201c<strong>Business Closure Calendar<\/strong>\u201d in the \u201c<strong>Calendar Rule<\/strong>\u201d entity and\u00a0not in the Calendar. Hence the records of the Business Closure are created only in the Calendar Rule entity as shown in the below screens:<\/p>\n<p style=\"text-align: justify;\"><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2014\/08\/img21.jpg\"><img decoding=\"async\" class=\"alignnone size-full wp-image-817\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2014\/08\/img21.jpg\" alt=\"img2\" width=\"424\" height=\"197\" \/><\/a><\/p>\n<p style=\"text-align: justify;\"><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2014\/08\/img31.jpg\"><img decoding=\"async\" class=\"alignnone size-full wp-image-818\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2014\/08\/img31.jpg\" alt=\"img3\" width=\"1257\" height=\"133\" \/><\/a><\/p>\n<p style=\"text-align: justify;\">\n<p style=\"text-align: justify;\">Now if you need to retrieve all the Business Closures, then you need to\u00a0follow the below steps:<\/p>\n<ul style=\"text-align: justify;\">\n<li>First you need to read the <strong>Calendar<\/strong> record where the name will be \u201c<strong>Business Closure Calendar<\/strong>\u201d. It will give you the Calendar Id, in our case the Calendar Id is \u201c<strong>2F3B356D-B21B-E411-80DB-00155D000819<\/strong>\u201d.<\/li>\n<li>Now you need to read all the Calendar Rules records, where Calendar Id will be \u201c<strong>2F3B356D-B21B-E411-80DB-00155D000819<\/strong>\u201d.<\/li>\n<\/ul>\n<p style=\"text-align: justify;\"><strong>2. <span style=\"text-decoration: underline;\">Default &amp; Inner Calendar type, and how it works for Weekly Schedule of Facility and User<\/span><\/strong>: When we define the weekly schedule for facility or users as shown below:<\/p>\n<p style=\"text-align: justify;\"><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2014\/08\/img41.jpg\"><img decoding=\"async\" class=\"alignnone size-full wp-image-819\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2014\/08\/img41.jpg\" alt=\"img4\" width=\"519\" height=\"401\" \/><\/a><\/p>\n<p style=\"text-align: justify;\">For this schedule, CRM then creates a record, with Type O (Default) in Calendar entity.<\/p>\n<p style=\"text-align: justify;\"><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2014\/08\/img51.jpg\"><img decoding=\"async\" class=\"alignnone size-full wp-image-820\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2014\/08\/img51.jpg\" alt=\"img5\" width=\"713\" height=\"88\" \/><\/a><\/p>\n<p style=\"text-align: justify;\">As shown in the above screen (<strong>Weekly schedule setting for facility<\/strong>), we have chosen the 5 day in a week rule, and Work Hours are 8:00 AM \u2013 5:00 PM. Hence it will create the another Calendar record with Type -1 (<strong>Inner Calendar<\/strong>) as shown below:<\/p>\n<p style=\"text-align: justify;\"><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2014\/08\/img61.jpg\"><img decoding=\"async\" class=\"alignnone size-full wp-image-821\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2014\/08\/img61.jpg\" alt=\"img6\" width=\"725\" height=\"117\" \/><\/a><\/p>\n<p style=\"text-align: justify;\">And for the combination of <strong>Inner<\/strong> Calendar Id \u201c<strong>FF4BEDC7-BE1B-E411-80DB-00155D000819<\/strong>\u201d and Calendar id \u201c<strong>766D0EA5-675F-4F9B-B972-F60908804B14<\/strong>\u201d, it creates the \u201c<strong>Weekly Single Rule<\/strong>\u201d in the Calendar Rule entity as shown in the below screenshot:<\/p>\n<p style=\"text-align: justify;\"><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2014\/08\/img71.jpg\"><img decoding=\"async\" class=\"alignnone size-full wp-image-822\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2014\/08\/img71.jpg\" alt=\"img7\" width=\"1239\" height=\"90\" \/><\/a><\/p>\n<p style=\"text-align: justify;\">And if we check the Calendar Rule for \u201c<strong>FF4BEDC7-BE1B-E411-80DB-00155D000819<\/strong>\u201d (<strong>Inner Calendar ID of 766D0EA5-675F-4F9B-B972-F60908804B14<\/strong>), then we find\u00a0that it only contains the Offset and Duration and that Offset and Duration helps us to create the start and end time of Schedule as shown in the below screen:<\/p>\n<p style=\"text-align: justify;\"><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2014\/08\/img8.jpg\"><img decoding=\"async\" class=\"alignnone size-full wp-image-823\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2014\/08\/img8.jpg\" alt=\"img8\" width=\"517\" height=\"90\" \/><\/a><\/p>\n<p style=\"text-align: justify;\">Hence, if we need to create the Start &amp; End Time of the Schedule, then we calculate it\u00a0from Offset and Duration as follows:<\/p>\n<p style=\"text-align: justify;\"><strong>Start Time<\/strong> = Offset\/60, hence in our case. It will be 480\/60 = 8:00AM<\/p>\n<p style=\"text-align: justify;\"><strong>End Time<\/strong> = (Offset + Duration)\/60 = (480 + 540)\/60 = 1020\/60 = 17 = 5:00 PM<\/p>\n<p style=\"text-align: justify;\">Now if you define any time Off in the schedule of Facility or User, it will create the record in the Calendar Rule, where the Description will be \u201c<strong>Time Off Rule<\/strong>\u201d as shown in the below screens:<\/p>\n<p style=\"text-align: justify;\"><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2014\/08\/img9.jpg\"><img decoding=\"async\" class=\"alignnone size-full wp-image-824\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2014\/08\/img9.jpg\" alt=\"img9\" width=\"630\" height=\"341\" \/><\/a><\/p>\n<p style=\"text-align: justify;\"><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2014\/08\/img10.jpg\"><img decoding=\"async\" class=\"alignnone size-full wp-image-825\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2014\/08\/img10.jpg\" alt=\"img10\" width=\"1053\" height=\"152\" \/><\/a>Now, if you need to programmatically read the \u201c<strong>Time Off<\/strong>\u201d of any resource (Facility or User), then you need to follow the below steps:<\/p>\n<ul style=\"text-align: justify;\">\n<li>Manually read the CalendarId from that resource.<\/li>\n<li>Then read all the records from Calendar Rule entity, based on that Calendar Id, and Description will be \u201c<strong>Time Off Rule<\/strong>\u201d. And then based on the Pattern, Duration, and Start Time, you can calculate the Time Off.<\/li>\n<\/ul>\n<p style=\"text-align: justify;\">Now, if you need to programmatically find the schedule of any facility between the given dates, then there are two ways of\u00a0doing it:<\/p>\n<ul style=\"text-align: justify;\">\n<li>Manually read the calendar rules for \u201c<strong>Weekly Single Rule<\/strong>\u201d and \u201c<strong>Time Off Rule<\/strong>\u201d based on Calendar ID, and based on the Pattern, Duration, and Offset create the Start and End Times. But this will be time consuming and not the best way.<\/li>\n<li>Hence for this, CRM itself provides a request with the name \u201c<strong>ExpandCalendarRequest<\/strong>\u201d. Using this request, you just need to give the Calendar Id, and Start and End date. And it will return the schedule of the Calendar between given dates including time off and business closures. \u00a0You need to write the following code for that:<\/li>\n<\/ul>\n<p style=\"text-align: justify;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 ExpandCalendarRequest req = new ExpandCalendarRequest();<\/p>\n<p style=\"text-align: justify;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 req.CalendarId = new Guid(&#8220;766D0EA5-675F-4F9B-B972-F60908804B14&#8221;);<\/p>\n<p style=\"text-align: justify;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 req.Start = DateTime.Now.AddDays(-20);<\/p>\n<p style=\"text-align: justify;\">\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0req.End = DateTime.Now.AddDays(20);<\/p>\n<p style=\"text-align: justify;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ExpandCalendarResponse res = (ExpandCalendarResponse)_service.Execute(req);<\/p>\n<p style=\"text-align: justify;\">In response, it will return an\u00a0array of schedules. If user is\u00a0available during\u00a0that time, then it displays the Time Code as \u201c<strong>Available<\/strong>\u201d, otherwise it will display the Time Code as \u201c<strong>Unavailable<\/strong>\u201d in that particular schedule.<a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2014\/08\/img111.jpg\"><img decoding=\"async\" class=\"alignnone size-full wp-image-826\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2014\/08\/img111.jpg\" alt=\"img11\" width=\"955\" height=\"306\" \/><\/a><\/p>\n<p style=\"text-align: justify;\"><strong>3. <span style=\"text-decoration: underline;\">Holiday Schedule<\/span><\/strong>: When you create a new Holiday Schedule in the CRM, it creates the new Calendar\u2019s record for the Calendar Entity, with type 2 as shown in the below screens:<\/p>\n<p style=\"text-align: justify;\"><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2014\/08\/img12.jpg\"><img decoding=\"async\" class=\"alignnone size-full wp-image-827\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2014\/08\/img12.jpg\" alt=\"img12\" width=\"657\" height=\"153\" \/><\/a> <a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2014\/08\/img13.jpg\"><img decoding=\"async\" class=\"alignnone size-full wp-image-828\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2014\/08\/img13.jpg\" alt=\"img13\" width=\"774\" height=\"87\" \/><\/a><\/p>\n<p style=\"text-align: justify;\">Same as Business Closure, if you create the records under Holiday, it will create the records of the Calendar Rule entity where Description will be \u201c<strong>Holiday Rule<\/strong>\u201d as shown below:<\/p>\n<p style=\"text-align: justify;\"><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2014\/08\/img14.jpg\"><img decoding=\"async\" class=\"alignnone size-full wp-image-829\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2014\/08\/img14.jpg\" alt=\"img14\" width=\"1233\" height=\"101\" \/><\/a><\/p>\n<p style=\"text-align: justify;\">Now if you need to retrieve all the Holiday Schedules, then you need to follow the steps below:<\/p>\n<ul style=\"text-align: justify;\">\n<li>First, you need to read the <strong>Calendar<\/strong> record where the Name will be the given name in your Holiday Schedule and Type will be 2.<\/li>\n<li>Then, read all the Calendar Rules for the corresponding Calendar Id.<\/li>\n<\/ul>\n<p style=\"text-align: justify;\"><strong>4. <span style=\"text-decoration: underline;\">Customer Service<\/span><\/strong>: When we create the Customer Service Calendar in the CRM, it creates 2 calendar records out of public view.<\/p>\n<p style=\"text-align: justify;\">One record is created with type 1 (<strong>Customer Service<\/strong>), and another is created with Type -1 (<strong>Inner Calendar<\/strong>). This is same as the <strong>Weekly Schedule<\/strong> of Facility or User. In the Customer Service Schedule, we can provide the \u201c<strong>Holiday Schedule<\/strong>\u201d as shown below:<\/p>\n<p style=\"text-align: justify;\"><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2014\/08\/img15.jpg\"><img decoding=\"async\" class=\"alignnone size-full wp-image-830\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2014\/08\/img15.jpg\" alt=\"img15\" width=\"530\" height=\"440\" \/><\/a><\/p>\n<p style=\"text-align: justify;\">Now if you need to programmatically read the Customer Service Schedule between the given dates, then you can use the Expand Calendar Request as we did the for the Facility \/ User Schedules.<\/p>\n<p style=\"text-align: justify;\"><strong>Note: <span style=\"text-decoration: underline;\">Using the Expand Calendar Request, you can\u2019t retrieve the Business Closers, Time Off and Holiday Schedule calendar\u2019s records between the given dates<\/span>.<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this blog, we have explained how CRM stores the records for calendar, and how can we programmatically retrieve them from CRM. In CRM 2013 SP 1, two new calendar types are introduced. With that, we now have the following 4 types of calendars in CRM: Type Name Description 0 Default This type uses for\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2014\/08\/calendars-and-expand-calendar-request-in-crm-2013-sp-1\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[21,22,24],"tags":[237,394,1418,1541,1649],"class_list":["post-815","post","type-post","status-publish","format-standard","hentry","category-dynamics-crm-2013","category-dynamics-crm-2015","category-dynamics-crm-2016","tag-calendar","tag-crm-2013-sp1","tag-records","tag-schedule","tag-spring-wave"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/815","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/comments?post=815"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/815\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=815"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=815"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=815"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}