Deploy custom workflows with site template

It is common scenario when you did some customizations, saved site as template and want to reuse it in SharePoint 2013 or in SharePoint Online (Office 365). Such site templates can include workflows with custom workflow actions. Unfortunately if you save site with custom workflow actions as template and then try to create new site you can receive such annoying error:

Error

Microsoft.Workflow.Client.ActivityNotFoundException:Theactivity named'WorkflowXaml_988fe3c3_dc3e_47a9_8ff3_c912c82eb56d'fromscope'/spo/216722f1-1dc0-4c6d-aafd-86b12ef60a14/1f87e1ae-da77-44d4-92d1-502507b5f2d4/34ceaf02-5217-46be-a307-e09dd93da230'wasnotfound.HTTP headers receivedfromthe server-ActivityId:224e672a-4e00-44ed-8b55-894a059608c2.NodeId:.Scope:.ClientActivityId:f6cadd9c-c011-1000-aa42-85eedd28fc19.--->System.Net.WebException:Theremote server returned an error

The reason of such behavior is related to incorrect processing of template by SharePoint 2013.

That's why it was implemented such utility because some of our customers had questions about correct site template provisioning. Especially when custom site template included workflow actions from our product Workflow Actions Pack .

Use case – deploy a new web with configured workflows

Save Site as Template

The first step, you need to create a Site template. To do this navigate to Site Settings ->Save site as Template (In Site Actions section). If you don’t see this link you can navigate usingdirect link. For example:https://yourSiteUrl/sites/WebUrl /_layouts/15/savetmpl.aspx

Then fill all the fields and check the checkbox “Include content” (If you don’t do thisthe workflows won’t be included into template).

When the operation will be completed, please download the WSP package from the solution gallery.

Click on the template to download it: .. image:: ../_static/img/deploy-custom-workflows-4.png

Patch the site template

As described earlier if we try to create a new site we can get the following error:

Error

Microsoft.Workflow.Client.ActivityNotFoundException:Theactivity named'WorkflowXaml_988fe3c3_dc3e_47a9_8ff3_c912c82eb56d'fromscope'/spo/216722f1-1dc0-4c6d-aafd-86b12ef60a14/1f87e1ae-da77-44d4-92d1-502507b5f2d4/34ceaf02-5217-46be-a307-e09dd93da230'wasnotfound.HTTP headers receivedfromthe server-ActivityId:224e672a-4e00-44ed-8b55-894a059608c2.NodeId:.Scope:.ClientActivityId:f6cadd9c-c011-1000-aa42-85eedd28fc19.--->System.Net.WebException:Theremote server returned an error

To avoid the error we have to patch the WSP package with help of a small utility TemplatePackageFix . I described it in detail in my previous article . This utility simply moves all workflows to separate feature. Thus, site will be created by template without workflows and then you will be able to activate the feature to deploy workflows.

You can download it from the following link . Please download it and extract to any directory.

To run, press “Win + R” and run the CMD.

Next step is to specify path to the program and path to the WSP package which we downloaded.The command can look like this:

c:YourFolderTempatePackageFix.exe

After a few seconds you will see “fixed” message:

That is all. Your WSP package has been patched, all workflows have beenmoved to another feature.The last step is to upload the WSP package to the solution gallery.

Create new Site based on saved template

Now you can upload patched wps package with site template to your solution gallery and activate it. Then,you can create a new site. To do thisthis navigate to “Site Contents”.

Then,scroll down and press “new subsite”:

Please fill all the fields and select your site template on “Custom” tab. Note, if you can’t find your site template, most likely you selected incorrect language.

The last step before you can use the site, you need to activate the “Workflow Actions Pack” feature (This will make available custom workflow actions) and “Template workflows” feature (it contains all your workflows).