12-04-2018 02:48 AM
I have a requirement that if a document has been deleted in the repository then all the workflow that are associated with it should get deleted (each workflow package will always have a single document). Originally, on delete of a document the workflow is left in a hanging state and the reference of the document gets removed from the workflow side (bpm_package).
I tried to implement this by using rule/action (items are deleted or leave this folder) - was able to find workflows in js and cancel them, but it does not delete the document nor the workflow. on checking the XHR request i was able to find out that a concurrency exception occurs between the action and onDelete policy.
how do i delete/cancel/close the associated workflows of a document
PFB script to cancel workflow
/**
* js function call on 'onDeleteNode' to cancel all running workflows
*/
function cancelWorkflow() {
var document = behaviour.args[0];
logger.warn("doc: " + document.name);document.activeWorkflows.forEach(function(activeWf) {
activeWf.cancel(); / / also tried activeWf.delete();
});
}
12-04-2018 07:20 AM
You have to combine both method in that policy.
beforeDeleteNode() will give the noderef and assign it as global variable use that noderef in onDeleteNode() method to delete that noderef.
12-04-2018 03:37 AM
Try implementing the same thing in beforeDeleteNode Policy .
12-04-2018 05:49 AM
You need to create Behavior/Policie to achieve this task.
http://docs.alfresco.com/6.0/references/dev-extension-points-behaviors.html
You can use beforeDeleteNode/onDeleteNode behaviour and write logic here to delete workflow.
Thanks
Sanjay
12-04-2018 06:47 AM
Krutik Jayswal i tried get the same error in rest with beforeDeleteNode -> JavaException: org.springframework.dao.ConcurrencyFailureException: Child association not found: 2178. A concurrency violation is likely.↵This can also occur if code reacts to 'beforeDelete' callbacks and pre-emptively deletes associations ↵that are about to be cascade-deleted. The 'onDelete' phase then fails to delete the association.↵See links on issue ALF-12358.
Sanjay Bandhniya on firing with onDeleteNode event - unable to get the nodeRef on the document.
12-04-2018 07:20 AM
You have to combine both method in that policy.
beforeDeleteNode() will give the noderef and assign it as global variable use that noderef in onDeleteNode() method to delete that noderef.
12-04-2018 08:03 AM
as far as i know - behavior/policies does not work like that.
could you please show me with an example - like i've mentioned in my question
12-04-2018 11:28 PM
Hello Abbas,
You can can cancel workflow on delete document by using behaviour/policies. Please refer following example.
public void beforeDeleteNode(final NodeRef nodeRef) {
List<WorkflowInstance> activeWorkflow = serviceRegistry.getWorkflowService().getWorkflowsForContent(nodeRef,true);
for (WorkflowInstance w : activeWorkflow) {
wIds.add(w.getId());
}}
public void onDeleteNode(ChildAssociationRef childAssocRef, boolean isNodeArchived) {
if (wIds.size() > 0) {
serviceRegistry.getWorkflowService().cancelWorkflows(wIds);
}
wIds.clear();
}
I have achieved that scenario using above solution. If you find better solution please share.
Thanks
Vidhi
12-05-2018 12:40 AM
thanks for the code sample. i'll try and update here
02-23-2021 06:38 AM
Hello @abbask01 , Did you manage to delete the associated workflows? I want to implement the same thing, could you please help me with that?
Explore our Alfresco products with the links below. Use labels to filter content by product module.