When developing SharePoint solutions, you must be able to migrate workflows both within the farm and from one SharePoint farm to another. A typical scenario is the transfer to a production environment of a workflow created in a test environment.
Consider various approaches to solving this problem.
Workflow Development in Visual Studio
This option places workflows in SharePoint solution files (* .wsp). This approach provides greater flexibility and ability to configure workflows, but in some cases using solutions like the Farm Solution can be unsafe in terms of the health and performance of the SharePoint farm.
Details on the development of workflows in Visual Studio can be found
here .
Create a package containing a workflow in SharePoint Designer 2013
The SharePoint Designer 2013 tool provides the ability to save a workflow to a template file. Saving a workflow to a template file is called a workflow packaging. The resulting template file can be imported to the target SharePoint server, eliminating the need to re-develop the workflow on the target server. Keep in mind the restrictions on the types of workflows that can be exported as a template:
- All types of workflows of the SharePoint Workflow 2013 platform
- Only reusable workflows of the SharePoint Workflow 2010 platform.
Since we do not plan to use an outdated model of workflows, this restriction is not fundamental for us. However, the resulting template file is the same * .wsp solution package as the package generated by Visual Studio, which means this approach has the same drawbacks as the previous one, if you deploy the packaged workflow directly.
Instead of direct deployment, we will use a template file to extract the metadata (workflow.xaml file) describing the workflow. We will be able to use this metadata to deploy the workflow using the alternatives described below.
Export workflow.xaml using SharePoint Designer- Use SharePoint Designer to open the site where the workflow to be migrated is deployed.
- In the Site Objects sidebar, select the Workflows menu item.
- Select the desired workflow in the list and click on the “Save As Template” ribbon item located in the “Management” group. The message: "The template is saved in the library" Site Assets ".".
- Select the menu item "All files" in the sidebar "Site Objects". In the list in the main viewing area, select an item named “Site Assets”. Press F5 to refresh the view.
- Select the item named "<workflow name> .wsp" and click on the "File Export" tape item located in the "Manage" group. Select the path to save the file.
- Open in Explorer (or another file manager) the folder where the * .wsp file was saved. Rename the file by changing the extension from “wsp” to “cab”.
- Open the file after renaming. Extract the file “workflow.xaml” from the contents of the archive. This can be done by simply dragging and dropping the file into the directory for extraction.
Using Provision Frameworks
Typical tasks associated with the migration and deployment of SharePoint development artifacts have led the developer community to create convenient tools for automating them. One such tool is the
SPMeta2 framework. It is a powerful tool for solving the deployment of SharePoint development artifacts, allowing you to use C # code writing instead of declarative description (XML). SPMeta2 supports many
work scenarios , including workflow scenarios.
The disadvantages of deploying through the framework include the need to create a separate project to use it even in simple cases where you can get by with PowerShell scripts.
')
Migrating workflows using PowerShell scripts
The PowerShell command console allows you to solve an extensive class of tasks related to the administration of SharePoint. Moreover: some tasks can be solved exclusively with the help of this tool.
To transfer the workflows of the list, a PowerShell script has been developed, accessible by
reference . The script uses the object of the
WorkflowServicesManager class to perform operations on workflows.
To deploy a workflow using a script, you need to get the file
workflow.xaml , which contains a description of the workflow. Above, we described a method for obtaining a
workflow.xml file using SharePoint Designer. However, it is easier to do this using the
ExtractWorkflowXaml function defined in the script. Function parameters:
Parameter | Description |
---|
$ url | The URL of the node associated with the Workflow service that contains the workflow |
$ wf_displayname | Workflow Name |
$ workflow_xaml_path | File path to save |
Example of using the function:
ExtractWorkflowXaml "http://mysp.com/source" "Test workflow" "C:\spmetadata\workflow.xaml"
To deploy a workflow, you must call the
DeployListWorkflow function. Function parameters:
Parameter | Description |
---|
$ workflow_xaml | Path to the .xaml file |
$ url | URL of the node associated with the Workflow service for which you want to create a workflow |
$ list_name | The name of the list with which the workflow should be associated. |
$ wf_displayname | Workflow Name |
$ overwrite | Sign of the need to rewrite the workflow definition if it already exists |
Example of using the function:
DeployListWorkflow "C:\spmetadata\workflow.xaml" "http://mysp.com/sandbox" "Test Workflow List" "My New Workflow" $true
Migrating workflows using PowerShell scripts allows you to accomplish a task without using third-party tools.
Advantages of this solution:
- You do not need to create a project in Visual Studio and write code that calls the framework for deployment, simply calling the function of the PowerShell script.
- Ability to extract workflow metadata by simply calling the functions of the PowerShell script.
- Logging actions during the deployment process makes it easy to localize and fix the error.
Cons of this solution:
- The script uses the SharePoint Server Object Model (SSOM), which means it must run on the server in the SharePoint farm. The script needs to be modified for the script to work using the client object model.
- The script adjusts only the basic attributes of the workflow necessary for its operation. To work with additional attributes, the script needs to be modified.
- In the current version, the script is designed to expand the workflow list. To work with other types of workflows, script modification is required.
The script is made the most simple in order to demonstrate the ability to deploy workflows through PowerShell. In the future we plan to expand the functionality of the described script.