Copy history from previous workflow to current workflow

The workflow was changed on my site. I need to copy the history from the previous workflow into the current workflow. Any guidance on how to do this would be appreciated


1 Like

Here is some exporter code of the workflow history (from collective.jsonify)

I assume that you need to iterate over all affected objects (catalog search by portal_type) and update their workflow_history attribute. data is supposed to be a you need to insert/copy its value under the name of the new workflow id and remove the old entry...something like that...

THank you for your response.

I have modified the following in the and it works

def get(self):
    print("Calling the get statement I changed and the contents of wfh")
    history = getattr(self.context, 'workflow_history', {})
    #wfh = history.get(self.wf_id) #original

    # Kaminie code starts
    workflowTool = getToolByName(self, "portal_workflow")
    workflowids = workflowTool.getWorkflowIds()  # get workflow ids
    wfh = history.get(self.wf_id)  #this is a tuple
    for id in workflowids:
        print("printing awfhistory")
        awfhistory = history.get(id)
        wfh = (*wfh, awfhistory)
    #originalwfh = history.get(self.wf_id)  #goes after the ones that i am adding
    #wfh = (*wfh, originalwfh)
    print("Printing wfh")
    if wfh:
        return wfh[-1]
    return None
    #mycode ends

    #if wfh:
    #    return wfh[-1]
    #return None

In case this is useful to anyone else, the changes I made return all history for an object. Some additional changes I had to make are to the following.

def default_workflow_history(context, workflow):
history = getattr(aq_base(context), 'workflow_history', {}) #added by me
return history.get(workflow.getId(), ()) #original return statement

and the following imports have to be added

from Products.CMFCore.utils import getToolByName #added by Kaminie

I realized copying the history would not serve my purpose, so I am just returning it.

Again Thanks you for your help.

1 Like