Over the last few weeks I’ve been working with one of my customers to create sites from a site request list. For each new client that they register a new site request is created and then a SharePoint Designer workflow calls a service that will create a site collection and then after that a PnP template is applied.

All quite easy stuff, however today I ran into a problem. I got the following error when a workflow was added to my site:

Error: Value cannot be null. Parameter name: input

When I tried to apply the templates using PnP PowerShell the template would simply work. So my templates are valid.

After a bit of debugging I found that the following lines in PnP Sites core’s objectWorkflows.cs are responsible for reading the workflow definition file:

// Load the Workflow Definition XAML
Stream xamlStream = template.Connector.GetFileStream(templateDefinition.XamlPath);
XElement xaml = XElement.Load(xamlStream);

The templateDefinition.XamlPath just contains the guid.xaml file name without any location

In this case I didn’t really want to add the path to my template xml file as that would be complicated to pass down to the pice of code that is running. Quite early on in the process the template is read and after that the file location is not relevant anymore.

What to do next?

Within my web service I’m running:

web.ApplyProvisioningTemplate(template, provisioningTemplateApplyingInformation);

I’m simply changing my current directory to  the template file and now the PnP Sites Core libraries pick up my Workflow file:

System.IO.Directory.SetCurrentDirectory(FillPathToTemplateFile);
web.ApplyProvisioningTemplate(template, provisioningTemplateApplyingInformation);

Why does this work with PnP PowerShell?

Within the PnP PowerShell code your path is adjusted while PnP-ProvisioningTemplate is running. This makes it possible to find the workflow file.

 

 

 

 

Advertisements