⬆️ ⬇️

Migrating and deploying SharePoint 2013 workflows

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:



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
  1. Use SharePoint Designer to open the site where the workflow to be migrated is deployed.
  2. In the Site Objects sidebar, select the Workflows menu item.
  3. 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 ".".
  4. 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.
  5. 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.
  6. 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”.
  7. 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:

ParameterDescription
$ urlThe URL of the node associated with the Workflow service that contains the workflow
$ wf_displaynameWorkflow Name
$ workflow_xaml_pathFile 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:

ParameterDescription
$ workflow_xamlPath to the .xaml file
$ urlURL of the node associated with the Workflow service for which you want to create a workflow
$ list_nameThe name of the list with which the workflow should be associated.
$ wf_displaynameWorkflow Name
$ overwriteSign 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:



Cons of this solution:



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.

Source: https://habr.com/ru/post/306228/



All Articles