1

I have successfully followed (well almost got this working) this blog, however I am stuck as I do not understand if i have 6 different site templates how to pick the one to apply. This is all feeding off a SharePoint list that we are using for Site Creation. In the list we have the department which matches the template that should be applied.

Do I need to create multiple functions? I do not know the next steps for this?

Any help would be appreciated!

1 Answer 1

1

No, we need to create six different functions, just create a single function in Azure and dynamically handle the parameters. And the function must have a site template parameter along with other site metadata (parameters like title, URL, owner, etc).

In your site creation configuration list one choice column should be "Select Template" where all six templates name should be as choice values. While users fill out this list form, they must select the template for that site from the dropdown list. Once the user submits this form through the power Automate(Microsoft Flow) it will go to the Azure queue, now in the Azure function pass all the parameters came from the SharePoint list - so, basically, it is needed only one Azure function.

Notes :

  • All the six PnP site templates should be copied to the Azure local drive, so based on the template in the Azure function, you need to apply the appropriate PnP template.

Update - how to implement the above approache - SharePoint Online site provisioning using Microsoft Flow, Azure Functions and Azure Storage Queue?

High-level steps as use cases:

  1. The user creates an item in a SharePoint list.
  2. Microsoft Flow will be triggered on item creation.
  3. Microsoft Flow will add a message on the Azure Storage Queue.
  4. The Azure Function will monitor the Azure Storage Queue and create the subsite based on the values entered in the SharePoint list using PowerShell.

In order to achieve the above use case - we need to follow the below steps:

  • Create SharePoint List
  • Get and register AppId and AppSecret in SharePoint Online
  • Create Azure Storage Queue
  • Create Azure Function
  • Create PowerShell Script
  • Test Azure Storage Queue
  • Create Microsoft Flow

In the Azure function, we need to write the below PowerShell code:

$requestBody = Get-Content $triggerInput -Raw | ConvertFrom-Json

$ParentSiteUrl = "https://spfire.sharepoint.com/sites/projectsitecreation/"

$WebTemplate = $requestBody.WebTemplate

$SiteTitle = $requestBody.SiteTitle

$SiteDescription = "Site with PowerShell"

$SiteURL = $requestBody.SiteURL

$SiteLanguage = $requestBody.SiteLanguage

$AppId = $env:AppId

$AppSecret = $env:AppSecret

connect-PnPOnline -AppId $AppId -AppSecret $AppSecret -url $ParentSiteUrl

New-PnPWeb -Title $SiteTitle -url $SiteURL -Locale $SiteLanguage -Template $WebTemplate -Description $SiteDescription

Write-Output "PowerShell script processed queue message '$requestBody'"

For the step by step details, refer to the below article - very well explained about the above use case:

SharePoint Online site provisioning using Microsoft Flow, Azure Functions and Azure Storage Queue

How to dynamically apply PnP-Provisioning template to the site?

Let's say you have three templates template 1, template 2, template 3 these will be in SharePoint custom list choice column value (template selection)... user will select any of the names of the templates from the SharePoint list.... then with the same name copy the actual three different templates in the Azure local drive like template1.xml, template2.xml,template3.xml.

Now create the site as the usual way using the PnP command, then finally call Apply-PnPProvisioningTemplate command and template name in the pathname should be dynamic which is coming from sp list... So if the user selects template 1 from the sp list, you need to pass this template name which is located at Azure local drive in the Apply-PnPProvisioningTemplate command.

Example: Post site creation step:

If the user selects template1 from the SharePoint list template selection choice column, then we need to call the Apply-PnPProvisioningTemplate like below:

Apply-PnPProvisioningTemplate -Path "Azure DrivePath Where this template is located""\template1.xml"

If the user selects template2 from the SharePoint list template selection choice column, then we need to call the Apply-PnPProvisioningTemplate like below:

Apply-PnPProvisioningTemplate -Path "Azure DrivePath Where this template is located""\template2.xml"

If the user selects template3 from the SharePoint list template selection choice column, then we need to call the Apply-PnPProvisioningTemplate like below:

Apply-PnPProvisioningTemplate -Path "Azure DrivePath Where this template is located""\template3.xml"
15
  • That is awesome news, so here is what I am showing in my run.ps1 script in azure { "callbackUrl":"", "Title":"sitetitle", "Url":"siteurl", "Owner":"siteowner", "Template":"STS#3" } When the whole script runs it gets stuck doing two things, 1st is applying the template and the 2nd is writing back to the original list it fails
    – Dorinda
    Apr 16, 2020 at 20:02
  • I would also like to run an additional script to put all of the system site collection admin into the new site as well. can i just add that?
    – Dorinda
    Apr 16, 2020 at 20:53
  • For your first query - first create the blank site, then apply the PnP Provisioning template... I am not clear about your second part of that question "writing back to original list" For your second question - applying PnP provisioning template to system site collection - if this is one time job, no conditional events to execute, then you just execute that script from your local machine itself, no need of Azure function.
    – SP 2022
    Apr 17, 2020 at 0:58
  • Part of the original instructions included in the blog I am following writes back the status to the Site Creation list in SharePoint. However I keep getting an error that it cant find the list Exception calling "ExecuteQuery" with "0" argument(s): "Cannot contact site at the specified URL /sites/SiteCreation/Lists/SiteCreation. There is no Web named "/sites/SiteCreation/Lists/SiteCreation/_vti_bin/sites.asmx"." and it never applies the template. It creates the site but doesnt do the rest?
    – Dorinda
    Apr 18, 2020 at 15:18
  • Also when I look at the xml it is not including all of the lists or the branding in the template....do these have to be applied seperatly? Sorry I just do not have experience doing this and appreciate the help.
    – Dorinda
    Apr 18, 2020 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.