{"id":29345,"date":"2021-09-15T16:20:10","date_gmt":"2021-09-15T10:50:10","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=29345"},"modified":"2021-10-07T11:20:53","modified_gmt":"2021-10-07T05:50:53","slug":"programmatically-know-the-time-control-status-using-the-getstate-method","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2021\/09\/programmatically-know-the-time-control-status-using-the-getstate-method\/","title":{"rendered":"Programmatically know the Time control Status using the GetState method"},"content":{"rendered":"<h2 style=\"text-align: justify;\"><strong>Introduction<\/strong><\/h2>\n<p style=\"text-align: justify;\">Often we use Dynamic 365 Time Control when we want to keep track of time based on a certain date.<\/p>\n<p style=\"text-align: justify;\">E.g. Whether a Lead has been qualified before the estimated close date etc.<\/p>\n<p style=\"text-align: justify;\">In this blog, we will see how we can programmatically get the status of the Time Control using form scripting.<\/p>\n<p style=\"text-align: justify;\">To know more about Time control and how to configure it, please follow this <a href=\"https:\/\/www.inogic.com\/blog\/2014\/06\/adding-timer-control-to-lead-entity-in-dynamics-crm-2013-spring-release\/\" target=\"_blank\" rel=\"noopener\">link<\/a>.<\/p>\n<p style=\"text-align: justify;\">In this example, I have configured the Time Control for Case Entity and on the load of the Form it will check the status of the Timer Control and show the Status as a Form Notification.<\/p>\n<p style=\"text-align: justify;\">If the case is resolved before the <strong>Resolve By<\/strong> period then it is considered under <strong>Success<\/strong> and similarly, if the case is in the <strong>Cancelled<\/strong> stage then it is considered as <strong>Failure<\/strong>.<\/p>\n<p style=\"text-align: justify;\"><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/09\/GetState-method1.png\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"aligncenter wp-image-29348 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/09\/GetState-method1.png\" alt=\"GetState method\" width=\"868\" height=\"677\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/09\/GetState-method1.png 868w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/09\/GetState-method1-300x234.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/09\/GetState-method1-768x599.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/09\/GetState-method1-660x515.png 660w\" sizes=\"(max-width: 868px) 100vw, 868px\" \/><\/a><\/p>\n<p style=\"text-align: justify;\"><strong>Syntax: formContext.getControl(\u201c&lt;Your Timer Control Name&gt;\u201d).getState()<\/strong>;<\/p>\n<p style=\"text-align: justify;\">The name property of the Timer Control would be the logical name.<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/09\/GetState-method2.png\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"aligncenter wp-image-29347 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/09\/GetState-method2.png\" alt=\"GetState method\" width=\"607\" height=\"558\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/09\/GetState-method2.png 607w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/09\/GetState-method2-300x276.png 300w\" sizes=\"(max-width: 607px) 100vw, 607px\" \/><\/a><\/p>\n<p style=\"text-align: justify;\"><strong>Code: <\/strong><\/p>\n<p style=\"text-align: justify;\">To check and show the Timer Control as Form Notification, I have registered a script on Load of the form.<\/p>\n<pre class=\"lang:css gutter:true start:1\">\/\/Register the function on the Form on Load event\r\nonLoad\u00a0=\u00a0(executionContext)\u00a0=&gt;\u00a0{\r\nlet\u00a0functionName:\u00a0string\u00a0=\u00a0\"onLoad\";\r\nlet\u00a0timeControlStatus:\u00a0number\u00a0=\u00a00;\r\ntry\u00a0{\r\n\/\/checking\u00a0execution\u00a0context\u00a0\r\nif\u00a0(executionContext\u00a0==\u00a0null)\u00a0{\r\nreturn;\r\n}\r\n\/\/getting\u00a0form\u00a0context\r\nlet\u00a0formContext\u00a0=\u00a0executionContext.getFormContext();\r\ntimeControlStatus\u00a0=\u00a0formContext.getControl(\"CaseResolution\").getState();\r\nthis.createFormNotificationBasedOnTimerStatus(timeControlStatus,\u00a0formContext)\r\n}\u00a0catch\u00a0(error)\u00a0{\r\nconsole.log(functionName\u00a0+\u00a0''\u00a0+\u00a0error);\r\n}\r\n}\r\n\/\/\u00a0Check\u00a0the\u00a0status\u00a0of\u00a0the\u00a0timer\u00a0control\u00a0and create notification accordingly\r\ncreateFormNotificationBasedOnTimerStatus\u00a0=\u00a0(timeControlStatus:\u00a0number,\u00a0formContext:\u00a0any)\u00a0=&gt;\u00a0{\r\nlet\u00a0functionName:\u00a0string\u00a0=\u00a0\"createFormNotificationBasedOnTimerStatus\";\r\nlet\u00a0formNotificationMsg:\u00a0string\u00a0=\u00a0\"\";\r\nlet\u00a0formNotificationLevel:\u00a0string\u00a0=\u00a0\"\";\r\nlet\u00a0uniqueId:\u00a0string\u00a0=\u00a0String(timeControlStatus);\r\ntry\u00a0{\r\nswitch\u00a0(timeControlStatus)\u00a0{\r\ncase\u00a01:<\/code>\r\n\/\/\u00a0Time\u00a0Value\u00a0:\u00a0Not\u00a0Set\r\nformNotificationMsg\u00a0=\u00a0\"Time\u00a0Value\u00a0:\u00a0Not\u00a0Set\";\r\nformNotificationLevel\u00a0=\u00a0\"INFO\";\r\nbreak;\r\ncase\u00a02:\r\n\/\/\u00a0Time\u00a0Value\u00a0:\u00a0In\u00a0progress\r\nformNotificationMsg\u00a0=\u00a0\"Case\u00a0Resolution:\u00a0Is\u00a0In\u00a0Progress\";<\r\nformNotificationLevel\u00a0=\u00a0\"INFO\";\r\nbreak;\r\ncase\u00a03:\r\n\/\/\u00a0Time\u00a0Value\u00a0:\u00a0Warning\r\nformNotificationMsg\u00a0=\u00a0\"Case\u00a0Resolution:\u00a0Kindly\u00a0Resolve\u00a0the\u00a0Case\u00a0at\u00a0earliest\";\r\nformNotificationLevel\u00a0=\u00a0\"WARNING\";\r\nbreak;\r\ncase\u00a04:\r\n\/\/\u00a0Time\u00a0Value\u00a0:\u00a0Violated\r\nformNotificationMsg\u00a0=\u00a0\"Case\u00a0Resolution:\u00a0Violated\";\r\nformNotificationLevel\u00a0=\u00a0\"WARNING\";\r\nbreak;\r\ncase\u00a05:\r\n\/\/\u00a0Time\u00a0Value\u00a0:\u00a0Success\r\nformNotificationMsg\u00a0=\u00a0\"Case\u00a0Resolution:\u00a0Compelted\u00a0Successfully\";\r\nformNotificationLevel\u00a0=\u00a0\"INFO\";\r\nbreak;\r\ncase\u00a06:\r\n\/\/\u00a0Time\u00a0Value\u00a0:\u00a0Expired\r\nformNotificationMsg\u00a0=\u00a0\"Case\u00a0Resolution:\u00a0Expired\";\r\nformNotificationLevel\u00a0=\u00a0\"ERROR\";\r\nbreak;\r\ncase\u00a07:\r\n\/\/\u00a0Time\u00a0Value\u00a0:\u00a0Canceled\r\nformNotificationMsg\u00a0=\u00a0\"Case\u00a0Resolution:\u00a0Canceled\";\r\nformNotificationLevel\u00a0=\u00a0\"ERROR\";\r\nbreak;\r\ncase\u00a08:\r\n\/\/\u00a0Time\u00a0Value\u00a0:\u00a0Paused\r\nformNotificationMsg\u00a0=\u00a0\"Case\u00a0Resolution:\u00a0Paused\";\r\nformNotificationLevel\u00a0=\u00a0\"INFO\";\r\nbreak;\r\ndefault:\r\nbreak;\r\n}\r\nformContext.ui.setFormNotification(formNotificationMsg,\u00a0formNotificationLevel,\u00a0uniqueId);\r\n} catch (error) {\r\nconsole.log(functionName\u00a0+\u00a0''\u00a0+\u00a0error);\r\n}\r\n}\r\n<\/pre>\n<p style=\"text-align: justify;\"><strong>Note:<\/strong><\/p>\n<p style=\"text-align: justify;\">As per <a href=\"https:\/\/docs.microsoft.com\/en-us\/powerapps\/developer\/model-driven-apps\/clientapi\/reference\/controls\/getstate\" target=\"_blank\" rel=\"noopener\">Microsoft docs<\/a> the Get State method returns the values as shown in the below table:<\/p>\n<table class=\"dcf-table dcf-table-responsive dcf-table-bordered dcf-table-striped\" style=\"height: 317px;\" width=\"236\">\n<thead>\n<tr>\n<th class=\"dcf-txt-center\" style=\"text-align: center;\" scope=\"col\">Returned Value<\/th>\n<th class=\"dcf-txt-center\" style=\"text-align: center;\" scope=\"col\">Status Value<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td class=\"dcf-txt-center\" style=\"text-align: center;\" data-label=\"Returned Value\">1<\/td>\n<td class=\"dcf-txt-center\" style=\"text-align: center;\" data-label=\"Status Value\">Not Set<\/td>\n<\/tr>\n<tr>\n<td class=\"dcf-txt-center\" style=\"text-align: center;\" data-label=\"Returned Value\">2<\/td>\n<td class=\"dcf-txt-center\" style=\"text-align: center;\" data-label=\"Status Value\">In progress<\/td>\n<\/tr>\n<tr>\n<td class=\"dcf-txt-center\" style=\"text-align: center;\" data-label=\"Returned Value\">3<\/td>\n<td class=\"dcf-txt-center\" style=\"text-align: center;\" data-label=\"Status Value\">Warning<\/td>\n<\/tr>\n<tr>\n<td class=\"dcf-txt-center\" style=\"text-align: center;\" data-label=\"Returned Value\">4<\/td>\n<td class=\"dcf-txt-center\" style=\"text-align: center;\" data-label=\"Status Value\">Violated<\/td>\n<\/tr>\n<tr>\n<td class=\"dcf-txt-center\" style=\"text-align: center;\" data-label=\"Returned Value\">5<\/td>\n<td class=\"dcf-txt-center\" style=\"text-align: center;\" data-label=\"Status Value\">Success<\/td>\n<\/tr>\n<tr>\n<td class=\"dcf-txt-center\" style=\"text-align: center;\" data-label=\"Returned Value\">6<\/td>\n<td class=\"dcf-txt-center\" style=\"text-align: center;\" data-label=\"Status Value\">Expired<\/td>\n<\/tr>\n<tr>\n<td class=\"dcf-txt-center\" style=\"text-align: center;\" data-label=\"Returned Value\">7<\/td>\n<td class=\"dcf-txt-center\" style=\"text-align: center;\" data-label=\"Status Value\">Canceled<\/td>\n<\/tr>\n<tr>\n<td class=\"dcf-txt-center\" style=\"text-align: center;\" data-label=\"Returned Value\">8<\/td>\n<td class=\"dcf-txt-center\" style=\"text-align: center;\" data-label=\"Status Value\">Paused<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 style=\"text-align: justify;\"><strong>Conclusion<\/strong><\/h2>\n<p style=\"text-align: justify;\">Thus by using the Get State method we can get the status of the timer control and use it as per our requirement, as we have used it to notify the user in\u00a0our example. In the below screenshot we can see the final result i.e. when the Timer control is set to the <strong>Nearing Expiry<\/strong> status a form notification gets set accordingly.<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/09\/GetState-method3.png\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"aligncenter wp-image-29346 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/09\/GetState-method3.png\" alt=\"GetState method\" width=\"1167\" height=\"579\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/09\/GetState-method3.png 1167w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/09\/GetState-method3-300x149.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/09\/GetState-method3-1024x508.png 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/09\/GetState-method3-768x381.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/09\/GetState-method3-660x327.png 660w\" sizes=\"(max-width: 1167px) 100vw, 1167px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/www.maplytics.com\/\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"aligncenter wp-image-27021 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/03\/maplytics.png\" alt=\"map dynamics 365\" width=\"800\" height=\"200\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/03\/maplytics.png 800w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/03\/maplytics-300x75.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/03\/maplytics-768x192.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/03\/maplytics-660x165.png 660w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Often we use Dynamic 365 Time Control when we want to keep track of time based on a certain date. E.g. Whether a Lead has been qualified before the estimated close date etc. In this blog, we will see how we can programmatically get the status of the Time Control using form scripting. To\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2021\/09\/programmatically-know-the-time-control-status-using-the-getstate-method\/\">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":[16,19,2361],"tags":[2396,2395],"class_list":["post-29345","post","type-post","status-publish","format-standard","hentry","category-dynamics-365","category-dynamics-crm","category-technical","tag-getstate-method","tag-time-control"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/29345","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=29345"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/29345\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=29345"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=29345"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=29345"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}