Caroline Sosebee is a Software Engineer at ThreeWill. She comes to us with 20+ years of software development experience and a broad scope of general IT support skills.
Background on why I needed to copy an approval workflow
Recently, one of our clients had a unique problem with workflows that required me to go into ALL the workflows, verify the email settings and correct them as needed. Since there were around 10 large approval workflows and several other basic notification workflows, this was no trivial task.
We’ve found in our experience that when changes are needed to an approval workflow, it’s best to make a new version of it in order to not disrupt any currently running approval workflows. One of the major pain points in copying an approval workflow is having to rebuild the custom task form associated with it. I REALLY didn’t want to have to do this for 8 to 10 workflows, each with their own custom task form filled with details. So I talked with co-workers, dug around on the internet and tested and played until I came up with a way to retain my custom forms. This post details out those steps (as well as how to copy the workflow itself). Of course, this is just one way to do it. I’m sure there are plenty of other ways that might be better, but this seems to work well for me. I hope it helps someone!
The problem itself that caused all this angst was an interesting one. It surfaced when our client acquired another company and joined the two domains. Suddenly there were two Active Directories being checked when an email was sent. The problem arose because some of the email recipients in the workflows were set to send to a ‘Display Name’ format instead of to an ‘Email address’ format. This meant that if an email is supposed to go to ‘John Doe’ and there is a ‘John Doe’ in both ADs, it was a crap shoot as to which John Doe would receive the email – the one from domain A or the one from Domain B. Definitely not the behavior we wanted! So all the workflows had to be checked and updated to be sure all emails were being sent to email addresses. Here are the steps I took to get these corrected.
Part 1 – Copying the approval workflow itself
One note before you start: I’m going to have you opening and closing SharePoint Designer for what feels like a million times. Do it even if you don’t feel like it. J SharePoint Designer does some really weird things with caching, etc. and this will help keep everything straight.
- Open the site in Microsoft SharePoint Designer.
- Click on the Workflows link on the left to display all the workflows, select the workflow you want to copy, right click it and select ‘Copy and Modify …’.
- Give it a new name and click OK. The workflow will open to the main workflow settings screen.
- Click Save to save any changes that may have been made in the background and then close this window (do NOT publish the workflow yet).
- Now go to All Files / Workflows and find the folder for the new workflow. It should contain three files.
(The three files you should find.)
- Click on the ‘xxx.xoml.wfconfig.xml’ file to open it and select ‘Edit file’.
- Since this is an approval workflow with an approval task, there will be a couple of references in this file to the task – we need to update these. When a workflow is copied, SharePoint renames any tasks it finds by tacking a ‘ Copy’ to the end of the existing name (only one in this case). So search this file for the text ‘Task Copy’ to find all the references and rename it to something new (but be sure to retain the ‘_Task’ in the name). Make sure to note what you named it for the next step.
- Now save the XML file and exit SharePoint Designer.
- Reopen SharePoint Designer and open your new workflow from the Workflows link, then click the ‘Edit’ button to open the workflow for editing.
- Find the ‘Start task process … ‘ statement and click on the ‘… Task Copy’ link. When it opens, click in the Name field and rename it to the same name you noted above. In this example, I renamed ‘BI_PreProduction_Approval_v3_Task Copy’ to ‘BI_PreProduction_Approval_v4_Task’.
- If you have other changes that need to be made to the workflow (that do not involve the task form), you can make them now. When done, save the changes and Publish the workflow. You now have a clean copy of the original workflow. On the workflow settings page for the copied workflow, you should see two generic forms that were created for you.
- The last step is to delete this new ‘Task’ form that was just created for you (in preparation for copying the original one). You do this by highlighting it and either pressing the Delete key or clicking the Delete button in the toolbar. You can ignore the form with a type of Association/Initiation (for this exercise anyway).
Part 2 – How to copy an existing custom task form to a new workflow
This is usually the painful part of copying a new workflow, as the custom task form is NOT copied with the rest of the workflow when you do a ‘Copy and Modify.’ This means you have to recreate it manually, which can be a major pain. Luckily, there is a way that allows you to reuse the old one in the new workflow. Here are the steps:
- In SharePoint Designer, open the old workflow to the main settings screen.
- Open the custom form you want to copy (will be of type ‘Task’) by clicking on its name. This will open the form in InfoPath.
- After it opens in InfoPath, click on File then Publish. Choose the ‘Export Source Files’ option and save them somewhere on your local drive where you can find them. A temp directory is fine.
- Close InfoPath, choosing ‘Don’t Publish’ when prompted.
- Close SharePoint Designer.
- Using Windows Explorer, navigate to the folder where you saved the InfoPath files.
- Right click the manifest.xsf file and open it using your favorite text editor.
- Within this file, search for all references to the original xsn file. I find it simplest to search for ‘.xsn’. There are a couple of things to change here:
- The path to the .xsn file – will need to match the path to your new workflow. You can verify this path within SharePoint Designer, under All Files.
- The name of the .xsn file – should be the same name as the workflow, with a ‘_Task’ following it. (You should follow the pattern used already for naming.)
- Save the file and close it.
- In Windows Explorer, right click the saved manifest.xsf file and select Design. This will open the file in InfoPath.
- Once open, we simply need to publish the form. If the name and path are set right, the form will be added to the new workflow. To publish, you can either click the ‘x’ in the top right corner and select ‘Save and Publish’ when prompted, or select File then Publish. If you choose this way, you can verify the location and name of the form to be published. If these look correct, click the ‘Workflow’ button to publish.
- Close InfoPath if it is still open.
- Re-open SharePoint Designer and connect to your site.
- Find the new workflow and open it to the main settings page. You should see your new custom form listed, along with the already existing Association form. To verify, click on the form to open it in InfoPath and your custom form will be displayed. You can now close InfoPath (choosing to publish or not).
- Back in SharePoint Designer, publish your workflow.
And that’s it! You now have a new copy of an old approval workflow and have retained the custom form you worked so hard to build in the original workflow. I hope this saves someone some of the headaches I’ve had in the past while copying workflows.