In SharePoint 2013 & SharePoint online, we can package and deploy all three types of workflows, List workflow, site workflow and reusable workflows, where as in SharePoint 2010 only Reusable workflow have this option. Let us discuss about SharePoint designer workflows the steps to package and deploy. For this,
• Let us open the SharePoint designer 2013.
• Here for example we are exporting Site Request Flow attached to Team Site Requests list.
• Select workflows from left navigation.
• Choose the workflow which you want to package and deploy across the environments.
• Click Save as a template, you will get a pop-up saying that, template has been saved to site assets library, please refer the screen shots below,

  • Click on Site assets from left navigation and you can see that wsp package has been created for that workflow.
  • Select the wsp file and click on Export file option from the ribbon and save that to your local drive.

  • Go to destination site in different environment, here I am deploying to different site collection.
  • First move the dependency lists from source site by saving list as list template and download the list to local machine.
  • Then go to the target site and select site settings under gear icon, Open List templates under Web designer galleries and upload the list template here.
  • Go ahead and create the lists using this template and name the lists as it’s in the Source site.

Then, go to site settings, open Solutions under web designer galleries.

  • Click on upload and upload the WSP which we have exported from designer and activate it.

This solution is having a feature at site level which will deploy the workflow. To see the feature, go to Manage Site features under site action and you can see that a feature as shown below,

  • Now activate the workflow feature, this it will get activate successfully.

NOTE: While activating the feature, possible to get below error,

Error may be due to the below reasons,

Reason 1: Number of Workflow Variables exceeds their limits

Workflow XAML failed validation due to the following errors:

Activity ‘Sequence’ has 51 variables, which exceeds the maximum number of variables per activity (50).

HTTP headers received from the server – Activity Id: 2bb3ba9e-28d3-4820-91a7-f03ebdb98fdf. NodeId: ZG-SP2013-02. Scope: /SharePoint/default/248fadea-e82b-4d15-bf03-d00b7947ca36/a6b8142a-8120-4823-a855-f400460ec143. Client ActivityId: e87640d8-8819-4981-bbdb-c46c02eb6d6f.

I counted variables in my workflow and indeed there are 51 variables defined in the workflow. All the variables are defined in root Sequence. Unfortunately, this is not documented in Workflow limitations web page on MSDN.

Solution:

Reorganize variables in multiple Sequences and reuse existing variables where possible.

Reason 2: WSPublishState value may be differ in Elements.xml file

The “Elements.xml” file, which is packaged within the “wsp” solution file contains 2 “<File” elements. One file element represents the XAML file, and the other represents the WF association file. If the WSPublishState value for each “<File” element differ (one has a value of “3” and the other a value of “1”), the error will occur. For solving your problem, please update the WSPublishState value for both “<File” elements to “3”.

PropertyName=”WSPublishState” Value=”3″

Also note that the WSPublishState property is also duplicated within the “MetaInfo” property, so both occurrences should be updated. Then the resulting files need to be re-packaged into the template.

Solution:

Prerequisites:

You can easily edit and modify a solution file from SharePoint using a simple zip with help of IZArc tool. Use the below link to download the tool.

Link to download IZArc : https://www.izarc.org/

Once installed, follow below steps to edit your wsp solution:

Change the extension of .wsp to .cab

  • Right click the file, and extract all the files as shown below,

 

 

You will find the folders similar like below,

 

  • Click “Site Request Flow2ListInstances” –> select “Elements” file.
  • Edit the file with your favorite editor, and just make sure both the WSPublishState property have “3” as shown below in both “workflow.xaml” & “WorkflowAssociation_” else correct it to 3, because sometimes WSPublishState property of “workflow.xaml” have value 1, so correct it to 3
  • Once you finish your changes open the IZArc tool, under file select “New Archive” and give a name to your new solution file as shown below,

  • Click Open and select the files required

click “Option” tab.

  • Under Options tab and select CAB on the Archiving Type option and then click OK.

  • Finally, the expected wsp will be derived, upload this updated wsp file to SharePoint and activate the feature in site level.

Ensure the below steps, before testing the workflow.

Go to the target list and open workflow settings and click on workflow

Workflow may be pointing to New Workflow History or Workflow History, if its “New Workflow History” change it to “Workflow History”, if its showing “Workflow History” just refresh the dropdown and set the “Workflow History” list and click Ok.

Finally, you have successfully moved the SP designer 2013 workflows for one environment to another.

Conclusion:

In this blog, you have learned how to Package and deploy SharePoint designer workflows across different environment