Nintex Workflow – Archiving a List Item with Workflow History
When you copy an item in SharePoint to another list, you lose the workflow history. The main reason, is that the workflows that ran on the original item, don’t exist in the destination list. Workflow history is linked to a specific workflow instance.
The process described in this post, is about getting the workflow history from an original item and specific workflow instance, and logging it to another workflow instance on the destination item. Not the ideal solution, but it’s better than nothing right?
What I’ve done though, is add the Workflow History logging into a User Defined Action. That way, it is reusable in any workflow. It also means you can reuse it multiple time in one workflow, to copy workflow history from multiple workflow instances.
There are number of ways to get this done. In this example, the business process (workflow) executes all the actions it needs. In the end of the workflow, it copies the current item to another list. But there is one final action. It starts a workflow on the newly copied item. It’s not a matter of just starting a workflow. That workflow must take some input parameters (start variables). These include the initial List Name, the initial Item ID and the current Workflow Name. This is enough information for the destination workflow to then get the Initial workflows history, parse it and store in the new item.
The workflow above is a generic approval process. But at the end of it, you’ll see the Copy Item and the Call Web Service action. In order to start a workflow on the new item that was copied, those parameters that we pass in, are passed through a piece of XML called Association Data.
The nodes inside the Data node are named, based on the Start Variables in the destination workflow that we are starting.
The Call Web Service, to start a workflow on the new item, call the Nintex Workflow web service.
Notice above, that the destination list where our item exists, is called Archive. This can be changed to your destination list. The destination workflow, I’ve named “Get Source Item Workflow History Workflow”. Finally, we put in our variable that contains the XML association data. Don’t forget to check the box “Encode Inserted Tokens”.
Now it’s time to take a look at the workflow that runs on that destination copied item.
The workflow is very simple. You can of course extend this, because all it has is one action. A User Defined Action is being used here. So lets move to the UDA and see what makes up the logic of that.
This is not a complex User Defined Action. This action has the same parameters as the workflow that is calling it. The List name, Item ID and workflow name. It then uses a Call Web Service action to again, call the Nintex Workflow web service, but this time we are calling the GetWorkflowHistoryForListItem. This will get all the workflow history for that item, for a specific workflow.
The results that come back are in XML form. So we use the Query XML action to pull the data out that we need.
I do want to point out that workflow history is stored based on a specific workflow instance. This process is going to take that workflow and now log it to a different workflow instance. But that is the result of this process. There’s no way to copy a workflow instance completely over to another list and another list item. Hopefully, this is a nice workaround for you.