{"id":12586,"date":"2018-08-06T16:30:31","date_gmt":"2018-08-06T11:00:31","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=12586"},"modified":"2022-07-19T16:27:52","modified_gmt":"2022-07-19T10:57:52","slug":"java-script-execution-context-provides-form-values-on-web-as-well-as-uci-in-dynamics-365-v9-0","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2018\/08\/java-script-execution-context-provides-form-values-on-web-as-well-as-uci-in-dynamics-365-v9-0\/","title":{"rendered":"JavaScript: \u201cExecution Context\u201d provides Form Values on Web as well as UCI in Dynamics 365 v9.0"},"content":{"rendered":"<h2><strong>Introduction:<\/strong><\/h2>\n<p style=\"text-align: justify;\">No doubt, Microsoft Dynamics 365 v9.0 surprised us with the UCI feature which provides a generic user interface to users, this is about UI but behind the scene for developers also Microsoft provided \u201cExecution Context\u201d object which is a collection of array.<\/p>\n<p style=\"text-align: justify;\">Recently we have a business requirement to perform some action using Custom button on contact and Dynamics 365 environment was v9.0.<\/p>\n<p style=\"text-align: justify;\">As we all know we can pass the Execution Context using \u201cPrimary Control\u201d CRM Parameter to Script function which we are calling on Click of Custom Button.<\/p>\n<p><img decoding=\"async\" class=\"wp-image-12587\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2018\/08\/1Java-Script-Execution-Context-provides-Form-Values-on-Web-as-well-as-UCI-in-Dynamics-365.png\" alt=\"Java Script Execution Context provides Form Values on Web as well as UCI in Dynamics 365\" width=\"975\" height=\"301\" \/><\/p>\n<p>So I did the same and got the \u201cexecutionContext\u201d in script and get the form context.<\/p>\n<p>Source code:<\/p>\n<pre class=\"lang:default decode:true \">function onClick(primaryControl)\r\n    \/\/function to build URL and open new window\r\n{\r\n    var functionName = \"onClick: \";\r\n   var executionContext = primaryControl;\r\n    try {\r\n        \/\/validate execution context\r\n        if (isValid(executionContext)) {\r\nvar formContext = executionContext.getFormContext();\r\n            \/\/get values\r\n            var firstname = isValid(formContext.getAttribute(\"firstname\")) &amp;&amp; isValid(formContext.getAttribute(\"firstname\").getValue()) ? \r\n        }\r\n    } catch (e) {\r\n        throwError(functionName, e.message);\r\n    }\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>It works on Classic Mode of Dynamics.<\/p>\n<p>Now I tried same with UCI mode by clicking same button and received error that \u201cexecutionContext.getFormContext is not a function\u201d.<\/p>\n<p><strong>Refer the below screenshot:<\/strong><\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-12588\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2018\/08\/2Java-Script-Execution-Context-provides-Form-Values-on-Web-as-well-as-UCI-in-Dynamics-365.png\" alt=\"Java Script Execution Context provides Form Values on Web as well as UCI in Dynamics 365\" width=\"970\" height=\"281\" \/><\/p>\n<p style=\"text-align: justify;\">Now, I debug and surprised that we can get field values which are on form within an executionContext itself only.<\/p>\n<p style=\"text-align: justify;\">By making following change in source code we used var executionContext = primaryControl; instead of var formContext = executionContext.getFormContext();. And I noticed that it works like charm in Classic as well as UCI mode of Dynamics 365 v9.0:<\/p>\n<pre class=\"lang:default decode:true\">function onClick(primaryControl)\r\n    \/\/function to build URL and open new window\r\n{\r\n    var functionName = \"onClick: \";\r\n   var executionContext = primaryControl;\r\n    try {\r\n        \/\/validate execution context\r\n        if (isValid(executionContext)) {\r\n            \/\/get values\r\n            var firstname = isValid(executionContext.getAttribute(\"firstname\")) &amp;&amp; isValid(executionContext.getAttribute(\"firstname\").getValue()) ? \r\n        }\r\n\r\n    } catch (e) {\r\n        throwError(functionName, e.message);\r\n    }\r\n}<\/pre>\n<p>For reference below are the properties we get when we pass \u201cPrimary Control\u201d parementer,<\/p>\n<p>Web:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-12589\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2018\/08\/3Java-Script-Execution-Context-provides-Form-Values-on-Web-as-well-as-UCI-in-Dynamics-365.png\" alt=\"Java Script Execution Context provides Form Values on Web as well as UCI in Dynamics 365\" width=\"974\" height=\"674\" \/><\/p>\n<p>UCI:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-12590\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2018\/08\/4Java-Script-Execution-Context-provides-Form-Values-on-Web-as-well-as-UCI-in-Dynamics-365.png\" alt=\"Java Script Execution Context provides Form Values on Web as well as UCI in Dynamics 365\" width=\"971\" height=\"211\" \/><\/p>\n<h2><strong>Conclusion<\/strong>:<\/h2>\n<p>We can get the form field values properties using executionContext itself in Dynamics 365.<\/p>\n<h2 style=\"text-align: left;\"><div class=\"su-heading su-heading-style-default su-heading-align-center\" id=\"\" style=\"font-size:15px;margin-bottom:5px\"><div class=\"su-heading-inner\">70% of global 2000 companies apply gamification to improve productivity and returns!<\/div><\/div><\/h2>\n<p><em><strong><a href=\"https:\/\/bit.ly\/3RD4lYW\" target=\"_blank\" rel=\"noopener noreferrer\">Gamifics365<\/a> <\/strong>\u2013 Spin the magic of games within Microsoft Dynamics 365 CRM to improve user adoption, enhance productivity, and achieve company goals!<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction: No doubt, Microsoft Dynamics 365 v9.0 surprised us with the UCI feature which provides a generic user interface to users, this is about UI but behind the scene for developers also Microsoft provided \u201cExecution Context\u201d object which is a collection of array. Recently we have a business requirement to perform some action using Custom\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2018\/08\/java-script-execution-context-provides-form-values-on-web-as-well-as-uci-in-dynamics-365-v9-0\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":13,"featured_media":12591,"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,18,19,33],"tags":[969,1740,1827],"class_list":["post-12586","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dynamics-365","category-dynamics-365-v9-2","category-dynamics-crm","category-javascript","tag-java-script","tag-uci-dynamics-365","tag-web-dynamics-365"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/12586","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=12586"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/12586\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media\/12591"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=12586"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=12586"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=12586"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}