{"id":4246,"date":"2015-12-21T20:05:20","date_gmt":"2015-12-21T19:05:20","guid":{"rendered":"http:\/\/contoso.se\/blog\/?p=4246"},"modified":"2016-01-04T10:57:33","modified_gmt":"2016-01-04T09:57:33","slug":"sharepoint-online-as-front-for-azure-automation","status":"publish","type":"post","link":"http:\/\/contoso.se\/blog\/?p=4246","title":{"rendered":"SharePoint Online as frontend for Azure Automation"},"content":{"rendered":"<p>Back in the Orchestrator days we had the Service Manager self-service portal that we could use to submit items that trigger runbooks in Orchestrator. The integration between Service Manager and Orchestrator worked great and the self-service portal brought a lot of value to automation scenarios. But time change and now we have a new executor in Azure Automation <span style=\"font-family: Wingdings;\">J<\/span><\/p>\n<p>The challenge is that there is no connector between Azure Automation and Service Manager or any other portal. In this blogpost we will look at how we can use SharePoint Online as a frontend to Azure Automation. The process of a new request will be:<\/p>\n<ol style=\"margin-left: 40pt;\">\n<li>User submits a new item in a SharePoint list<\/li>\n<li>A SharePoint workflow trigger a Azure Automation runbook<\/li>\n<li>Azure Automation does magic<\/li>\n<li>Azure Automation update the list item in SharePoint<\/li>\n<li>The user sees the result in the SharePoint list<\/li>\n<\/ol>\n<h2>Setting up SharePoint<\/h2>\n<ol style=\"margin-left: 40pt;\">\n<li>Sign-in to <a href=\"https:\/\/products.office.com\/en-us\/sharepoint\/sharepoint-online-collaboration-software\">SharePoint online<\/a><\/li>\n<li>Add a custom list, click on the Add list tile<br \/>\n<img decoding=\"async\" src=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2015\/12\/122115_1905_SharePointO1.png\" alt=\"\" \/><\/li>\n<li>Download and install <a href=\"https:\/\/www.microsoft.com\/en-us\/download\/details.aspx?id=35491\">SharePoint Designer<\/a> on your workstation<\/li>\n<li>Once you have installed SharePoint Designer, click on Edit List in the List toolbox, SharePoint Designer will start and load your SharePoint site<br \/>\n<img decoding=\"async\" src=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2015\/12\/122115_1905_SharePointO2.png\" alt=\"\" \/><\/li>\n<li>In SharePoint Designer click Edit List columns<\/li>\n<li>In the Edit List view, use the Add New Column and Column Settings to configure the list as you need it to be. In my example I have a list with a number of fields that are needed to create a new service account in Active Directory. I have also added a column named Result that Azure Automation use to write back the result from the runbook. There is also a column named Azure Automation Status that is used to report back the response when submitting the job to Azure automation. The SP Workflow and the column will be automatic created when we connect a workflow to the list.<\/li>\n<li>When the list is as you like it, click SAVE and go back to SharePoint and refresh the page<\/li>\n<\/ol>\n<p>The list is now created. You can click New Item in the list view and submit new items. You can click Edit this view and add the ID column. The runbook will use the ID field to keep track of which list item to work with.<\/p>\n<h2>Setting up Azure Automation<\/h2>\n<p>Next step is to setup the Azure Automation runbook and configure the webhook. More general information about webhooks can be found <a href=\"https:\/\/azure.microsoft.com\/en-us\/documentation\/articles\/automation-webhooks\/\" target=\"_blank\">here<\/a>.<\/p>\n<ol>\n<li>First thing we need to do is configure Azure Automation with a SharePoint Online module. Tao Yang have a <a href=\"http:\/\/blog.tyang.org\/2014\/12\/10\/using-azure-automation-build-microsoft-opsmgr-mp-catalog-sharepoint-online\/\" target=\"_blank\">good blog post<\/a> about this. Tao blogpost is about import the module in SMA, but that you should not try to do <span style=\"font-family: Wingdings;\">J<\/span> instead only follow Tao steps to build the ZIP file. You can download his ZIP file and then you add the two DLL files that he also link too.<\/li>\n<li>Once you have the complete ZIP file, browse to your automation account in Azure Automation and click on Assets and then Modules<\/li>\n<li>On the Modules page, click Add a module, and upload the ZIP file. Remember that if you are planning to use a Hybrid worker the module must be installed on all hybrid workers too<br \/>\n<img decoding=\"async\" src=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2015\/12\/122115_1905_SharePointO3.png\" alt=\"\" \/><\/li>\n<li>After the module is imported you need to setup a connection to your SharePoint site, for example. Remember that the service account used cannot be configured with two factor authentication, the account also has to have permissions on the SharePoint site.<br \/>\n<img decoding=\"async\" src=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2015\/12\/122115_1905_SharePointO4.png\" alt=\"\" \/><\/li>\n<li>I have put together an example runbook for this scenario, which can be found <a href=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2016\/01\/SP_ServiceAccount-1.txt\">here<\/a>. It will first show\/output you all data that comes from the webhook. It will then connect to SharePoint and get the current list and list item. In the end of the runbook an account is created and a hash table is created to update back into SharePoint. Either use my example runbook or build a new runbook.<\/li>\n<li>Next step, after the runbook is in place, is to create a webhook, click on the runbook, click webhook and add a new webhook. Remember to copy the webhook URL before clicking Create<\/li>\n<\/ol>\n<h2>Configure the SharePoint workflow<\/h2>\n<p>It is now time to configure the SharePoint workflow that will trigger the runbook when a new list item is created.<\/p>\n<ol>\n<li>Open SharePoint Designer and load your SharePoint site<\/li>\n<li>In SharePoint Designer, click Lists and Libraries on the left side, then click on your list<\/li>\n<li>On the right side on SharePoint Designer, click New\u00e2\u20ac\u00a6 next to Workflows<\/li>\n<li>Name the new workflow, for example Workflow 0003 in my example. Use SharePoint 2013 Workflow as platform type<\/li>\n<li>When the workflow is created, configure it to start automatically when a new item in the list is created<br \/>\n<img decoding=\"async\" src=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2015\/12\/122115_1905_SharePointO5.png\" alt=\"\" \/><\/li>\n<li>Click Edit Workflow to start build the new workflow<\/li>\n<li>The runbook, when complete, should look like this<br \/>\n<img decoding=\"async\" src=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2015\/12\/122115_1905_SharePointO6.png\" alt=\"\" \/><\/li>\n<li>The first step is to build a Directory, map list fields with variables<br \/>\n<img decoding=\"async\" src=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2015\/12\/122115_1905_SharePointO7.png\" alt=\"\" \/><\/li>\n<li>\n<div>Next step is call the runbook webhook, paste the webhook URL. Remember to change to HTTP POST<\/div>\n<p><img decoding=\"async\" src=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2015\/12\/122115_1905_SharePointO8.png\" alt=\"\" \/><\/li>\n<li>The last step in the workflow post the response from Azure Automation back to a column in a list. When the workflow do the HTTP POST to trigger the runbook a message is sent back, that is the message that you will write back to a column. This will be a simple log if the job has been submitted to Azure Automation successfully<br \/>\n<img decoding=\"async\" src=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2015\/12\/122115_1905_SharePointO9.png\" alt=\"\" \/><\/li>\n<li>When all steps in the workflow are configured, click SAVE and then PUBLISH in SharePoint Designer.<\/li>\n<\/ol>\n<h2>Testing 1-2-3<\/h2>\n<p>We have now built a list in SharePoint, we have built a workflow in SharePoint that will invoke a runbook. The runbook performs some action, in this example it creates an AD account, and sends the results back to the list in SharePoint.<\/p>\n<p>We fill in the list item. I guess that with a bit more SharePoint skills it would be possible to hide the two last test fields when filling in the information. Those two fields are only used to store status.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2015\/12\/122115_1905_SharePointO10.png\" alt=\"\" \/><\/p>\n<p>After a couple of seconds we can see that the workflow has run (Stage1) and that there is a response from Azure Automation when triggering the webhook (Accepted)<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2015\/12\/122115_1905_SharePointO11.png\" alt=\"\" \/><\/p>\n<p>In Azure Automation we can see that the jobs has completed. We can see a lot of info as Output from the runbook. In a production runbook you might want to scale down all the extra code and output <span style=\"font-family: Wingdings;\">J<\/span><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2015\/12\/122115_1905_SharePointO12.png\" alt=\"\" \/><\/p>\n<p>If we go back to SharePoint and do a refresh we can see there is a result saying the account already exists in AD and no new account has been created. If we submit a new item with request for another account is works, the new account is created <span style=\"font-family: Wingdings;\">J<\/span><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2015\/12\/122115_1905_SharePointO13.png\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2015\/12\/122115_1905_SharePointO14.png\" alt=\"\" \/><\/p>\n<p>If you would like to add approval steps to your solution, read more <a href=\"https:\/\/support.office.com\/en-sg\/article\/All-about-Approval-workflows-078c5a89-821f-44a9-9530-40bb34f9f742\">here<\/a>.<\/p>\n<p>OMS\u00c2\u00a0black belt\u00c2\u00a0Jakob also have great ideas about using SharePoint Online that I recommend, read it <a href=\"http:\/\/blog.coretech.dk\/jgs\/december-1st-azure-automation-triggering-a-webhook-from-a-sharepoint-workflow-using-out-of-the-box-activities\/\">here<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Back in the Orchestrator days we had the Service Manager self-service portal that we could use to submit items that trigger runbooks in Orchestrator. The integration between Service Manager and Orchestrator worked great and the self-service portal brought a lot of value to automation scenarios. But time change and now we have a new executor &hellip; <a href=\"http:\/\/contoso.se\/blog\/?p=4246\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[64],"tags":[],"_links":{"self":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4246"}],"collection":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4246"}],"version-history":[{"count":9,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4246\/revisions"}],"predecessor-version":[{"id":4259,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4246\/revisions\/4259"}],"wp:attachment":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4246"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4246"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4246"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}