1

I'm making a custom workflow, and I want to share the file that I create a workflow with the assignees, because otherwise, the users only access the file through "I've recently modified" and when the task is done, the file disappears.

How can I share the file when I create the workflow with assignees?

Thanks in advance.

PRVS
  • 1,612
  • 4
  • 38
  • 75
  • What exactly do you mean with "share with assignees"? Do you want the assignees to gain rights to change the file? Do you want the assignees to receive a task with a link to the file? – Stefan De Laet Mar 04 '16 at 11:53
  • I want that assignees have the file in the "share files " for example or "my files" @StefanDeLaet . – PRVS Mar 04 '16 at 14:10

1 Answers1

1

Use a executionflowlistener on start of workflow that gets the nodes in your workflowpackage and then adds the "user home" noderef as a secondary parent.

Get workflow package nodes :

 ActivitiScriptNode packageItemsbpm = (ActivitiScriptNode) execution.getVariable(BPM_PACKAGE);
List<ChildAssociationRef> packageitemAssociations =  nodeService.getChildAssocs(packageItemsbpm.getNodeRef()); 

Then iterate these wf package nodes, and add them to the assignees home folders:

for(String assigneeName : assigneesList) {
    ResultSet rs = getServiceRegistry().getSearchService().query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_LUCENE, "PATH:\"/app:company_home/app:user_homes/cm:"+ assigneeName  +"\"");
    if(rs.length() > 0){
          NodeRef assigneeHome = rs.getNodeRef(0);                                        
          nodeService.addChild(assigneeHome, nodeRef, ContentModel.ASSOC_CONTAINS, nodeService.getPrimaryParent(nodeRef).getQName());
    }
 }
Stefan De Laet
  • 1,409
  • 11
  • 20
  • But this shared files is the shared files of the assignees that I attach in my workflow? I can't understand how can I get the noderefs of these. – PRVS Mar 07 '16 at 10:33
  • The shared folder is shared between everyone. If you want to share with a limited number of users, you should do the above with the user home of the individual assignees. You can find the noderefs of these homefolders by using a path search , example PATH:"/app:company_home/app:user_homes/cm:mjackson" – Stefan De Laet Mar 07 '16 at 10:56
  • Only one thing, packageNode is the nodeRef of the file attached to the workflow? – PRVS Mar 07 '16 at 14:52
  • yes, correct. you can find these like this: ActivitiScriptNode packageItemsbpm = (ActivitiScriptNode) execution.getVariable(BPM_PACKAGE); return nodeService.getChildAssocs(packageItemsbpm.getNodeRef()); – Stefan De Laet Mar 08 '16 at 08:27
  • The two first parameters of the function createAssociation are NodeRef. How can I create a nodeRef to the path of the homefolders? I'm trying this: `NodeRef assigneesNodeRef = assignees.get(i).getNodeRef(); nodeService.createAssociation(assigneesNodeRef, nodeRef, ContentModel.ASSOC_CONTAINS);` but this not gives to me the path. – PRVS Mar 08 '16 at 16:00
  • And of course, I obtain an error: `Found 1 integrity violations: The association source type is incorrect: Source Node: workspace://SpacesStore/b2f97e3b-f3c8-4c60-852a-0d14783943a0 Association: Association[ class=ClassDef[name={http://www.alfresco.org/model/content/1.0}folder], name={http://www.alfresco.org/model/content/1.0}contains, target class={http://www.alfresco.org/model/system/1.0}base, source role=null, target role=null] Required Source Type: {http://www.alfresco.org/model/content/1.0}folder Actual Source Type: {http://www.alfresco.org/model/content/1.0}content` – PRVS Mar 08 '16 at 16:01
  • Can you help me with a solution for this? – PRVS Mar 08 '16 at 16:02
  • I ve updated the answer. try using the nodeService.addChild(...) method instead – Stefan De Laet Mar 09 '16 at 08:32