The Site design JSON schema supports an action called triggerFlow which, thankfully, be used to trigger a Logic App, not just a Flow. Aside from it making sense to allow this since Flow is built on Logic Apps, it's an important win because the Logic App authoring experience is more mature than Flow. The Logic Apps route banks you superior UI performance, expandable action outputs during review of individual job/run history, 'dark mode' via azure settings, and CLI administration (see importing and exporting logic apps) via the https://deanbot.dev/[Install az](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest text: azure cli).

Trigger Logic App in SharePoint site script

The following site script includes an example triggerFlow action:

{
  "$schema": "schema.json",
  "actions": [
    {
      "verb": "triggerFlow",
      "url": "<flow URL here>",
      "name": "Customize Site",
      "parameters": {
        "event": "Site Design",
        "product": "SharePoint Online"
      }
    }
  ]
}

To retrieve the URL to use for replacing <flow URL here> create a new Logic App with the "When a HTTP request is received" trigger and save. The HTTP POST URL can now be copied and pasted into the site script.

Receive Site Url and connect to SharePoint site in PowerShell Runbook

Typically, a runbook triggered from a site script applies customizations to the SharePoint site where the site design was applied. There may be other input parameters for the runbook, but it most probably includes at least the URL of the site to customize.

The following example runbook accepts a Url parameter, and then uses SharePoint PnP Powershell Cmdlets to connect to this SharePoint site prior to performing customization.

Param(
  # Url of site to execute provisioning on
  [Parameter(Mandatory = $true)]
  [string]$Url
)

# Variables
$AppClientId = Get-AutomationVariable -Name 'ClientId'
$AppClientSecret = Get-AutomationVariable -Name 'ClientSecret'

# Login
Write-Output ("Connecting to SharePoint Online '" + $Url + "'")
Connect-PnPOnline -AppId $AppClientId -AppSecret $AppClientSecret -Url $Url
if ( $? -ne 0 ) {
  $connected = $true
  Write-Output ("[[ Connected to SPO ]]")
}
else {
  Write-Output "Problem connecting to $Url"
  $connected = $false
}

# Execute Customization
if ($connected) {
  # Customize site here
  Write-Output "Todo customize $Url"
}
Write-Output "Process Complete!"

Trigger Runbook Job from Logic App

Continue necessary Logic App steps to trigger the runbook execution with from the Logic App. The URL of the site triggering this process will be passed along as a runbook parameter.

  1. Configure add the following Request Body JSON Schema:
    {
     "properties": {
         "webUrl": {
             "type": "string"
         }
     },
     "type": "object"
    }
  2. Add a Create job action (inside Azure Automation category).
  3. Connect if necessary, and then fill in Subscription, Resource Group, Automation Account values.
  4. Select Add a new parameter, select Runbook Name, and then select the desired runbook.
  5. Add the Runbook Parameter URL parameter to the action and populate with the, dynamic content, webUrl value.

All done.

Make sure you've applied your site script & design to SharePoint and trigger your flow by applying the site design.


Last updated