PRVS
PRVS

Reputation: 1690

Revert to the version of the document before workflow - Alfresco

In my custom workflow, I make some changes to PDF when I create the workflow:

<activiti:executionListener event="start" class="pt.entp.fields.CreateFields"></activiti:executionListener>

I want, when I cancel the workflow, the workflow clear the changes that were made when it created. No way to do this?

Upvotes: 0

Views: 268

Answers (1)

Stefan De Laet
Stefan De Laet

Reputation: 1419

First store your current version in the start workflow listener:

    NodeRef myPdfnode = ...
    String currentversion = serviceRegistry.getVersionService.getCurrentVersion(myPdfnode).getVersionLabel(); 
    execution.setVariable("mynode_currentversion", currentversion);

You will need to restore the version of the pdf document using an end workflow listener

 <activiti:executionListener event="end"
 class="pt.entp.fields.WorkflowEnded"></activiti:executionListener>

In there, check if the workflow was indeed cancelled, then restore to the version you saved:

 String deleteReason = execution.getDeleteReason();

     if ("cancelled".equals(deleteReason)){
       NodeRef myPdfnode = ...
       String initialversionLabel = execution.getVaraible("mynode_currentversion");
       Version initialversion = serviceRegistry.getVersionService.getVersionHistory(myPdfnode).getVersion(initialversionLabel );
       serviceRegistry.getVersionService.revert(myPdfnode, initialversion);
     }

Upvotes: 2

Related Questions