{"id":26695,"date":"2021-02-08T13:05:14","date_gmt":"2021-02-08T13:05:14","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=26695"},"modified":"2022-07-01T14:43:15","modified_gmt":"2022-07-01T09:13:15","slug":"using-environment-variables-in-dynamics-365-crm-part-1","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2021\/02\/using-environment-variables-in-dynamics-365-crm-part-1\/","title":{"rendered":"Using Environment Variables in Dynamics 365 CRM &#8211; Part 1"},"content":{"rendered":"<h2>Introduction<\/h2>\n<p style=\"text-align: justify;\">It\u2019s quite often we come across scenarios where we require some configuration settings to accomplish a requirement in Dynamics 365 CRM\/Power Apps. To overcome this requirement we create a custom entity with few fields in it and then we create a record to store the required configuration details.<\/p>\n<p style=\"text-align: justify;\">For example, let\u2019s say we want to integrate our Dynamics 365 CRM with an external system using the API and we have three instances of our CRM (i.e. the Dev, UAT, and Production). However, we have 3 different APIs as well, each specific to a respective CRM instance. To make sure our process uses the right API for the right instance, we have to store the API URL in the respective instances so we create a custom entity and use it to store the URL as a record. This is how we assured that the respective CRM instance used the respective API URL.<\/p>\n<p style=\"text-align: justify;\">This may not be the best possible way but some time back this was the only way until Microsoft came up with Environment Variables.<\/p>\n<p style=\"text-align: justify;\">Now using environment variables you can achieve all the above without going through all the fuss.<\/p>\n<p style=\"text-align: justify;\"><strong>So let\u2019s understand the background of this to get a clear picture:<\/strong><\/p>\n<p style=\"text-align: justify;\">\u2022 Microsoft has created 2 entities\/tables named \u201c<strong>Environment Variable Definitions<\/strong>\u201d and \u201c<strong>Environment Variable Values<\/strong>\u201d.<br \/>\n\u2022 The purpose of these entities\/tables is to store the environment variables created for your organization as records which means you can create more than one environment variable for your organization.<br \/>\n\u2022 The 2 entities (i.e. \u201cEnvironment Variable Definitions\u201d and \u201cEnvironment Variable Values\u201d) are related to each other. The \u201cEnvironment Variable Definitions\u201d has a 1:N or rather a 1:1 relation with the \u201cEnvironment Variable Values\u201d. The reason we are saying this is because you cannot have more than one value for one definition.<\/p>\n<p>Why do we need 2 entities to maintain the environment variables? Let\u2019s understand their purpose while we take you through the creation process of the variable. We will create an environment variable named \u201cApi URL\u201d to store the respective API end points for respective CRM instances.<\/p>\n<p>\u2022 First, make note that you must navigate to your solutions via Power Apps to create the environment variables. You cannot create or even view an Environment Variable from the classic window of your solutions.<br \/>\n\u2022 Once you are logged in to your <a href=\"https:\/\/make.powerapps.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Power Apps<\/a>, on the left pane, click on <strong>Solutions<\/strong>.<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/1-environment-variables.jpeg\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-26699 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/1-environment-variables.jpeg\" alt=\"Environment Variables\" width=\"1920\" height=\"895\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/1-environment-variables.jpeg 1920w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/1-environment-variables-300x140.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/1-environment-variables-768x358.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/1-environment-variables-1024x477.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/1-environment-variables-660x308.jpeg 660w\" sizes=\"(max-width: 1920px) 100vw, 1920px\" \/><\/a><\/p>\n<p>\u2022 Click on <strong>New<\/strong> button and then <strong>Environment Variable<\/strong><\/p>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/2-environment-variables.jpeg\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-26700 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/2-environment-variables.jpeg\" alt=\"Environment Variables\" width=\"1341\" height=\"512\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/2-environment-variables.jpeg 1341w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/2-environment-variables-300x115.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/2-environment-variables-768x293.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/2-environment-variables-1024x391.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/2-environment-variables-660x252.jpeg 660w\" sizes=\"(max-width: 1341px) 100vw, 1341px\" \/><\/a><\/p>\n<p>\u2022 You will be redirected to the following window<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/3-environment-variables.jpeg\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-26701 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/3-environment-variables.jpeg\" alt=\"\" width=\"1103\" height=\"566\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/3-environment-variables.jpeg 1103w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/3-environment-variables-300x154.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/3-environment-variables-768x394.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/3-environment-variables-1024x525.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/3-environment-variables-660x339.jpeg 660w\" sizes=\"(max-width: 1103px) 100vw, 1103px\" \/><\/a><\/p>\n<p>Here, you need to enter the values in the following<\/p>\n<p>&#8211; <strong>Display Name:<\/strong> As the name suggests, this will be the display name of the variable.<br \/>\n&#8211; <strong>Name:<\/strong> This is the schema name for the variable. You can actually query on the entity \u201cenvironmentvariabledefinitions\u201d and find the value entered in name under property \u201cschemaname\u201c<br \/>\n&#8211; <strong>Description:<\/strong> This will store any details you want to mention to describe the purpose of this environment variable.<br \/>\n&#8211; <strong>Data Type:<\/strong> There are 4 datatype options at the moment which are \u201cDecimal number\u201d, \u201cJSON\u201d, \u201cText\u201d, \u201cYes\/No\u201d.<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/4-environment-variables.jpeg\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-26702 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/4-environment-variables.jpeg\" alt=\"Environment Variables\" width=\"325\" height=\"217\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/4-environment-variables.jpeg 325w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/4-environment-variables-300x200.jpeg 300w\" sizes=\"(max-width: 325px) 100vw, 325px\" \/><\/a><\/p>\n<p>As per our example we would be creating the variable with following details:<\/p>\n<p>&#8211; <strong>Display Name:<\/strong> Api URL<br \/>\n&#8211; <strong>Name:<\/strong> new_apiurl<br \/>\n&#8211; <strong>Description:<\/strong> This variable will hold the URL of the API<br \/>\n&#8211; <strong>Data Type:<\/strong> Text<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/5-environment-variables.jpeg\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-26703 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/5-environment-variables.jpeg\" alt=\"Environment Variables\" width=\"328\" height=\"352\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/5-environment-variables.jpeg 328w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/5-environment-variables-280x300.jpeg 280w\" sizes=\"(max-width: 328px) 100vw, 328px\" \/><\/a><\/p>\n<p>Note: Like any other tables and columns, the environment variable as well takes the publisher prefix of the solution.<\/p>\n<p>\u2022 Once you select the Data Type, you start seeing 2 new fields i.e. Default Value and Current Value. The purpose of these 2 fields will be to store the value in this variable.<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/6-environment-variables.jpeg\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-26705 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/6-environment-variables.jpeg\" alt=\"Environment Variables\" width=\"325\" height=\"241\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/6-environment-variables.jpeg 325w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/6-environment-variables-300x222.jpeg 300w\" sizes=\"(max-width: 325px) 100vw, 325px\" \/><\/a><\/p>\n<p>The Default Value as the name suggests stores the value which you want the variable to return by default when there\u2019s no other value overriding the Default Value. The Current Value is the value that overrides the Default Value. In our scenario, the API URLs for the respective instances will go in Current Value.<\/p>\n<p><strong>Note:<\/strong> In the start of this blog we mentioned that Microsoft has created 2 entities\/tables \u201cEnvironment Variable Definitions\u201d and \u201cEnvironment Variable Values\u201d to store the environment variables, this is because the Current Value gets stored as a record in the \u201cEnvironment Variable Values\u201d table and is associated to the record created in table \u201cEnvironment Variable Definitions\u201d which consists of the remaining details like default value, name, and description of the variable.<\/p>\n<p>\u2022 Enter the values and hit Save, your environment variable will get created.<\/p>\n<p>You can move the same environment variables from one environment to another but instead have different Current Value in different environments.<\/p>\n<p><strong>To do this, you need to follow the below steps:<\/strong><\/p>\n<p>\u2022 In the source environment, navigate to <a href=\"https:\/\/make.powerapps.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Power Apps<\/a> -&gt; <strong>Solutions<\/strong> -&gt; <strong>Environment Variable<\/strong>.<br \/>\n\u2022 Edit the variable to remove the existing Default and Current value and save. Export the solution with this variable.<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/7-environment-variables.jpeg\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-26704 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/7-environment-variables.jpeg\" alt=\"Environment Variables\" width=\"1850\" height=\"931\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/7-environment-variables.jpeg 1850w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/7-environment-variables-300x151.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/7-environment-variables-768x386.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/7-environment-variables-1024x515.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/7-environment-variables-660x332.jpeg 660w\" sizes=\"(max-width: 1850px) 100vw, 1850px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/8-environment-variables.jpeg\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-26706 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/8-environment-variables.jpeg\" alt=\"Environment Variables \" width=\"1912\" height=\"968\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/8-environment-variables.jpeg 1912w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/8-environment-variables-300x152.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/8-environment-variables-768x389.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/8-environment-variables-1024x518.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/8-environment-variables-660x334.jpeg 660w\" sizes=\"(max-width: 1912px) 100vw, 1912px\" \/><\/a><\/p>\n<p>\u2022 Now in the other environment (where you plan to move this variable), navigate to <a href=\"https:\/\/make.powerapps.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Power Apps<\/a> -&gt; <strong>Solutions<\/strong><br \/>\n\u2022 Import the solution with the environment variable.<br \/>\n\u2022 While you import the solution you shall get a prompt as shown below, asking for the value for your variable.<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/9-environment-variables.jpeg\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-26707 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/9-environment-variables.jpeg\" alt=\"Environment Variables \" width=\"1911\" height=\"939\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/9-environment-variables.jpeg 1911w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/9-environment-variables-300x147.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/9-environment-variables-768x377.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/9-environment-variables-1024x503.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/9-environment-variables-660x324.jpeg 660w\" sizes=\"(max-width: 1911px) 100vw, 1911px\" \/><\/a><\/p>\n<p>You can either enter the value immediately or edit the field later.<\/p>\n<p><strong>Note:<\/strong><\/p>\n<p style=\"text-align: justify;\">&#8211; You will get the prompt to enter a value on solution import only if the variable has neither a Default Value nor a Current Value. If you just removed the Current Value before exporting the solution you will not get this prompt while importing the solution. However, you can edit the variable later to add the Current Value.<\/p>\n<p style=\"text-align: justify;\">&#8211; You get this prompt irrespective of the solution being of the type Managed or Unmanaged solution.<\/p>\n<p style=\"text-align: justify;\">&#8211; In case the environment variable is part of a managed solution, it cannot be edited later to add or update the Current Value.<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/10-environment-variables.jpeg\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-26708 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/10-environment-variables.jpeg\" alt=\"Environment Variables \" width=\"1915\" height=\"933\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/10-environment-variables.jpeg 1915w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/10-environment-variables-300x146.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/10-environment-variables-768x374.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/10-environment-variables-1024x499.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/02\/10-environment-variables-660x322.jpeg 660w\" sizes=\"(max-width: 1915px) 100vw, 1915px\" \/><\/a><\/p>\n<h2>Conclusion<\/h2>\n<p style=\"text-align: justify;\">Environment variable is a better way to hold the configuration details required by our environment and pass it on to other environments as well with different values in it.<\/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\">One Pic = 1000 words! Analyze data 90% faster with visualization apps!<\/div><\/div><\/h2>\n<p style=\"text-align: left;\"><em>Get optimum visualization of Dynamics 365 CRM data with &#8211;<\/em><br \/>\n<em><strong><a href=\"https:\/\/bit.ly\/3lYvozZ\" target=\"_blank\" rel=\"noopener noreferrer\">Kanban Board<\/a> <\/strong>\u2013 Visualize Dynamics 365 CRM data in Kanban view by categorizing entity records in lanes and rows as per their status, priority, etc.<\/em><br \/>\n<em><strong><a href=\"https:\/\/bit.ly\/3lCSBaA\" target=\"_blank\" rel=\"noopener noreferrer\">Map My Relationships<\/a><\/strong> \u2013 Map My Relationships \u2013 Visualize connections and relationships between Dynamics 365 CRM entities or related records in a Mind Map view.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction It\u2019s quite often we come across scenarios where we require some configuration settings to accomplish a requirement in Dynamics 365 CRM\/Power Apps. To overcome this requirement we create a custom entity with few fields in it and then we create a record to store the required configuration details. For example, let\u2019s say we want\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2021\/02\/using-environment-variables-in-dynamics-365-crm-part-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":[16,19,44],"tags":[2590,2171,545,592,2148,1337,1975,2589],"class_list":["post-26695","post","type-post","status-publish","format-standard","hentry","category-dynamics-365","category-dynamics-crm","category-power-apps","tag-canvas-apps-more","tag-dataverse","tag-dynamics-365-crm","tag-dynamics-crm","tag-environment-variables","tag-power-apps","tag-power-automate","tag-top-blogs-of-2021-power-apps"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/26695","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=26695"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/26695\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=26695"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=26695"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=26695"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}