Exporting and importing workflows

In Nintex Workflow 2013, you can use service operations from the Workflow web service to export and import workflows. The ExportWorkflow service operation exports an existing saved or published workflow, and a variety of service operations can save or publish an exported workflow, depending on the desired persistence and validation functionality.

Exporting a workflow

The ExportWorkflow service operation exports the definition of a site, reusable, or list workflow as a string, containing an XML representation of the Nintex workflow. The XML representation is the same format used in Nintex Workflow 2013 export (.nwf) files, which can be created from the Workflow designer. For more information about creating export files, see Export files.

Note: Nintex recommends that you do not manipulate the contents of an export file. Unpredictable results may occur. Use the ExportWorkflow service operation solely as a retrieval and persistence mechanism for workflows.

Importing a workflow

You can import an exported workflow by using the various service operations available to save or publish workflows to SharePoint. There isn't a separate service operation for importing workflows.

If you haven't saved the string returned by the ExportWorkflow service operation as an export file, you can use the SaveFromNWFXml or PublishFromNWFXml service operations, and their variants, to save or publish the string without converting it to a byte array. Otherwise, you can use a StreamReader to read the export file as a byte array, and then use the SaveFromNWF or PublishFromNWF service operations, or their variants, to save or publish the imported workflow.

For more information about saving and publishing workflows, see Saving and publishing workflows.

Example

The following method demonstrates how to copy a list workflow from one list to another list in SharePoint, by using the ExportWorkflow and PublishFromNWFXml service operations.

public bool CopyListWorkflow(string workflowName, string sourceListName, string targetListName) 
{
    // Export the workflow from the source list to a StringBuilder object, and then 
    // import the workflow from the StringBuilder object to the target list.
    try
    {
        // First, export the workflow to a StringBuilder object.
        var sb = new StringBuilder(
            soapClient.ExportWorkflow(
                workflowName,
                sourceListName,
                "list")
            );

        // Now, import the workflow from the StringBuilder object. The PublishFromNWFXml
        // service operation is configured so that it does not save the workflow
        // if the workflow cannot be published.
        if(sb.Length > 0)
        {
            return soapClient.PublishFromNWFXml(
                sb.ToString(),
                targetListName,
                workflowName + "_Copy",
                false);
        } 
        else 
        {
            return false;
        }
    }
    catch
    {
        return false;
    }
}

See Also

Concepts

Export files

Operations

Creating and deleting workflows

Reference

Web Service Reference