{"id":12038,"date":"2018-06-18T17:51:31","date_gmt":"2018-06-18T12:21:31","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=12038"},"modified":"2019-07-10T09:38:35","modified_gmt":"2019-07-10T09:38:35","slug":"integrating-dynamics-365-with-azure-functions-part-3","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2018\/06\/integrating-dynamics-365-with-azure-functions-part-3\/","title":{"rendered":"Integrating Dynamics 365 with Azure Functions &#8211; Part 3"},"content":{"rendered":"<p style=\"text-align: justify;\"><strong><img decoding=\"async\" class=\"aligncenter wp-image-12057\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2018\/06\/Copy-of-Clone-Multiple-Quotes-or-Invoices-in-Dynamics-365-CRM-in-a-One-Click-15-1.png\" alt=\"Integrating Dynamics 365 with Azure Functions Part 3\" width=\"821\" height=\"470\" \/><\/strong><\/p>\n<p style=\"text-align: justify;\"><strong>Introduction:<\/strong><\/p>\n<p style=\"text-align: justify;\">In\u00a0our <a title=\"Integrating Dynamics 365 with Azure Functions \u2013 Part 2\" href=\"https:\/\/www.inogic.com\/blog\/2018\/06\/integrating-dynamics-365-with-azure-functions-part-2\/\" target=\"_blank\" rel=\"noopener noreferrer\">last post<\/a> about\u00a0Azure functions, we saw how to register the workflow assembly and execute the workflow using Microsoft Flow in Dynamics 365. Continuing with our series to call webhooks from CRM, let us register the Azure function created as a Webhook. We register this using the Plugin Registration Tool (PRT)<\/p>\n<p style=\"text-align: justify;\">From the PRT choose Register\u00a0\u2192 Register New Webhook<\/p>\n<p style=\"padding-left: 40px;\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-19629\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2018\/06\/Integrating-Dynamics-365-with-Azure-Functions-2.png\" alt=\"Integrating Dynamics 365 with Azure Functions\" width=\"300\" height=\"317\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2018\/06\/Integrating-Dynamics-365-with-Azure-Functions-2.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2018\/06\/Integrating-Dynamics-365-with-Azure-Functions-2-284x300.png 284w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p style=\"text-align: justify;\">In the Endpoint URL provide the function URL.<\/p>\n<p style=\"text-align: justify;\">Choose Authentication method as WebhookKey and provide the key. This key is what you passed as the code querystring earlier.<\/p>\n<blockquote><p>Note: Webhook is registered as Service End Point in CRM<\/p><\/blockquote>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-19626\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2018\/06\/1Integrating-Dynamics-365-with-Azure-Functions.png\" alt=\"Integrating Dynamics 365 with Azure Functions\" width=\"548\" height=\"217\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2018\/06\/1Integrating-Dynamics-365-with-Azure-Functions.png 548w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2018\/06\/1Integrating-Dynamics-365-with-Azure-Functions-300x119.png 300w\" sizes=\"(max-width: 548px) 100vw, 548px\" \/><\/p>\n<p>You can now register a step for this webhook just like we do for a plugin assembly.<\/p>\n<p style=\"padding-left: 40px;\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-19628\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2018\/06\/2Integrating-Dynamics-365-with-Azure-Functions.png\" alt=\"Integrating Dynamics 365 with Azure Functions\" width=\"338\" height=\"366\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2018\/06\/2Integrating-Dynamics-365-with-Azure-Functions.png 338w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2018\/06\/2Integrating-Dynamics-365-with-Azure-Functions-277x300.png 277w\" sizes=\"(max-width: 338px) 100vw, 338px\" \/><\/p>\n<p style=\"text-align: justify;\">When you create an Account the PluginExecutionContext is received in the message body of the httprequest in your Azure function. You then need to parse that to get context related details.<\/p>\n<p style=\"text-align: justify;\">Once registered as webhook, you can also invoke this through a workflow by executing the endpoint using the following code:<\/p>\n<pre class=\"lang:default decode:true \">string serviceEndPoint = WebhookURL.Get(executionContext);\r\n                IWorkflowContext context = executionContext.GetExtension&lt;IWorkflowContext&gt;();\r\n\r\n                string fetch = @\"&lt;fetch&gt;\r\n                  &lt;entity name='serviceendpoint' &gt;\r\n                    &lt;attribute name='serviceendpointid' \/&gt;\r\n                    &lt;attribute name='name' \/&gt;\r\n                    &lt;attribute name='authtype' \/&gt;\r\n                    &lt;attribute name='url' \/&gt;\r\n                    &lt;filter type='and'&gt;\r\n                      &lt;condition attribute='contract' operator='eq' value='8' \/&gt;\r\n                      &lt;condition attribute='url' operator='eq' value='\" + serviceEndPoint + @\"' \/&gt;\r\n                    &lt;\/filter&gt;\r\n                  &lt;\/entity&gt;\r\n                &lt;\/fetch&gt;\";\r\n                EntityCollection coll = crmWorkflowContext.OrganizationService.RetrieveMultiple(new FetchExpression(fetch));\r\n\r\n                if (coll != null &amp;&amp; coll.Entities.Count &gt; 0)\r\n                {\r\n                    IServiceEndpointNotificationService endpointService =\r\n                             executionContext.GetExtension&lt;IServiceEndpointNotificationService&gt;();\r\n\r\n                    crmWorkflowContext.Trace(\"serviceEndPoint found: \" + coll.Entities[0].Id.ToString());\r\n                    endpointService.Execute(coll.Entities[0].ToEntityReference(), context);\r\n                }\r\n<\/pre>\n<p style=\"text-align: justify;\">Once again you receive the Workflow context in the message body that you can parse to read the information passed.<\/p>\n<p style=\"text-align: justify;\"><strong>Conclusion:<\/strong><\/p>\n<p style=\"text-align: justify;\">There are other ways to invoke Azure functions from D365. Azure functions can be called through Logic Apps and you could register Logic Apps on D365 entities and actions. That\u2019s content for another post. So Keep visiting this space \ud83d\ude42<\/p>\n<p><a href=\"https:\/\/www.maplytics.com\/multi-language-map-dynamics-crm-365\/\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-11613\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2018\/04\/Generate-Your-Own-New-Leads-Now-Within-Dynamics-365-CRM-with-Maplytics-11.png\" alt=\"Generate Your Own New Leads Now Within Dynamics 365 CRM with Maplytics\" width=\"820\" height=\"205\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction: In\u00a0our last post about\u00a0Azure functions, we saw how to register the workflow assembly and execute the workflow using Microsoft Flow in Dynamics 365. Continuing with our series to call webhooks from CRM, let us register the Azure function created as a Webhook. We register this using the Plugin Registration Tool (PRT) From the PRT\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2018\/06\/integrating-dynamics-365-with-azure-functions-part-3\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":13,"featured_media":12051,"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":[5,16,18,19],"tags":[542],"class_list":["post-12038","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-azure-functions","category-dynamics-365","category-dynamics-365-v9-2","category-dynamics-crm","tag-dynamics-365-azure-functions"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/12038","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=12038"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/12038\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media\/12051"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=12038"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=12038"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=12038"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}