{"id":3371,"date":"2018-10-09T10:42:07","date_gmt":"2018-10-09T10:42:07","guid":{"rendered":"http:\/\/himbap.com\/blog\/?p=3371"},"modified":"2018-11-13T19:57:38","modified_gmt":"2018-11-13T19:57:38","slug":"dynamics-365-ce-and-azure-function-part-1","status":"publish","type":"post","link":"https:\/\/himbap.com\/blog\/?p=3371","title":{"rendered":"Dynamics 365 CE and Azure Function Part 1"},"content":{"rendered":"<p><strong>Introduction<\/strong><br \/>\nThis is our first article in the series, of Dynamics 365 and Azure function integration. We will be discussing how we can import data from\u00a0CSV file to Dynamics 365 using an Azure function, during these series we will be discussing the following options,<\/p>\n<p>1. Introduction to Azure Function<br \/>\n2. Connecting Azure function to Dynamics 365<br \/>\n3. Setup Server to Server authentication between Azure and Dynamics 365<br \/>\n4. Deleting blob storage after function execution.<br \/>\n5. Trigger Azure function from Microsoft Flow.<\/p>\n<p>In this article, we will be discussing basic details about azure function.<\/p>\n<p><strong>What is Azure Function?<\/strong><\/p>\n<p>In a simple definition Azure function is a piece of code which can be executed on demand or can be bound to some event just like traditional SQL triggers, where we have some code that executes because of some event. The beauty of Azure function is its serverless capability which means you don\u2019t need special infrastructure to host and manage it and you need to only pay when your function is executing.<\/p>\n<p>An azure function can be the lifesaver sometimes when we want to keep our Dynamics 365 CE integration logic out of Dynamics 365 CE and we don\u2019t have any infrastructure to host that logic. We can use an Azure function for the different type of integration based on the business requirements. In our series, we are going to discuss importing data into Dynamics 365 with the help of an Azure function. An azure function can be written in Visual Studio and deployed to Azure or we can directly create an Azure function in the Azure portal. In our example, we are going to write Azure Function in Azure Portal. So let\u2019s get started.<\/p>\n<p>If you don\u2019t have a Dynamics 365 CE environment, you can follow our earlier article to <a href=\"https:\/\/himbap.com\/blog\/?p=2503\">setup 30 days trial<\/a> and can also setup a free <a href=\"https:\/\/azure.microsoft.com\">Microsoft Azure trial<\/a>.<\/p>\n<p>While building any azure component it is recommended to create them under a particular resource group so that it can be managed efficiently as a group. So let&#8217;s first create our resource group.<\/p>\n<p><strong>Connect to your Azure environment and create Resource Group using the following steps.<\/strong><\/p>\n<p><a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/10\/azure1.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-3399 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/10\/azure1-300x133.png\" alt=\"azure1\" width=\"300\" height=\"133\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/10\/azure1-300x133.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/10\/azure1-624x276.png 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/10\/azure1.png 858w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><strong>Once the resource group is created, we can add an azure function like following.<\/strong><br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/10\/azure2.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-3400 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/10\/azure2-300x212.png\" alt=\"azure2\" width=\"300\" height=\"212\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/10\/azure2-300x212.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/10\/azure2-624x440.png 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/10\/azure2.png 821w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Now we have your azure function app and we can add a function which can be associated with the different trigger, for our requirement we are going to use blob trigger which will trigger azure function as soon as a new excel file will be uploaded to azure blob storage, so click on + and create blob trigger<\/p>\n<p><a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/10\/azure3.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-3402 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/10\/azure3-300x128.png\" alt=\"azure3\" width=\"300\" height=\"128\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/10\/azure3-300x128.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/10\/azure3-1024x436.png 1024w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/10\/azure3-624x266.png 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/10\/azure3.png 1128w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>When blob trigger is added, we will get a run.csx file which is a c# script file where we are going to write our code logic.<br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/10\/azure4.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-3404 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/10\/azure4-300x51.png\" alt=\"azure4\" width=\"300\" height=\"51\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/10\/azure4-300x51.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/10\/azure4-624x106.png 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/10\/azure4.png 851w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Our azure function trigger execution will start from Run method which takes the following three parameters.<\/p>\n<p><strong>Stream<\/strong>&#8211; This will hold our blob storage (CSV file in our case)<br \/>\n<strong>name<\/strong> &#8211; This will be the name of the CSV file<br \/>\n<strong>TraceWrite<\/strong> &#8211; We can use this class to generate logging.<\/p>\n<p>Now we got an overview of the azure function, In the next article we are going to discuss code to read CSV file and upload it to Dynamics 365 so stay tuned !!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction This is our first article in the series, of Dynamics 365 and Azure function integration. We will be discussing how we can import data from\u00a0CSV file to Dynamics 365 using an Azure function, during these series we will be discussing the following options, 1. Introduction to Azure Function 2. Connecting Azure function to Dynamics 365 3. Setup Server to&#8230; <a href=\"https:\/\/himbap.com\/blog\/?p=3371\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":3407,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[491,21,402,522],"tags":[654,669,404,671,670,660],"_links":{"self":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3371"}],"collection":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3371"}],"version-history":[{"count":10,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3371\/revisions"}],"predecessor-version":[{"id":3409,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3371\/revisions\/3409"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/media\/3407"}],"wp:attachment":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3371"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3371"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3371"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}