cancel
Showing results for 
Search instead for 
Did you mean: 

Folder/Space as Workflow Package

hyperation
Champ on-the-rise
Champ on-the-rise
Hi Everyone,

I am wondering if there is a way to attach folder/space (along with the contents within) into a workflow package.

I know that to attach a node to the package we do something like:


var workflowPackage = workflow.createPackage();
workflowPackage.addNode(node);  // 'node' is the ScriptNode of the object (a document in this case).

But, that doesn't seem to work for folders? or does it??

Thanks
Smiley Happy
19 REPLIES 19

sebp
Champ in-the-making
Champ in-the-making
It does work. But the problem is that folders in workflow packages are not displayed by the dialogs. E.g. have a look at the getResources() method of org.alfresco.web.bean.workflow.ManageTaskDialog. You can see there is a developers note saying: "// NOTE: folders within workflow packages are ignored for now".
I also tried to add folders to workflow packages, but first you have to change all the backing beans of the workflow dialogs to make the folders be displayed in the Workflow Dialogs. Then you will realize that also the workflow dialog jsp pages have to be changed to display the folders correctly. Thats where I gave up.
Instead I allow the users to start a workflow on a folder. Then I made this folder the workflow package by overriding some code in StartWorkflowWizard.finishImpl()

hyperation
Champ on-the-rise
Champ on-the-rise
Thanks for the response sebp.

Can you provide some information on how your workaround was achieved?

Where is the StartWorkflowWizard.finishImpl()?

Thanks
Smiley Happy

sebp
Champ in-the-making
Champ in-the-making
Ok, first you have to make sure that workflows can be started on folders. Therefore create/open your web-client-config-custom.xml and add:


    <config>
        <actions>
            <action-group id="space_browse_menu">
                <action idref="start_workflow" />
            </action-group>
        </actions>
    </config>

into the <alfresco-config> element. If you restart Alfresco you should see the 'Start Advanced Workflow' option in the space browse menu.
Second, to make sure that the folder on which the user started the advanced workflow is taken as the workflow-package you have to change the class StartWorkflowWizard.java. To do this:

  • Download the Alfresco SDK for your Alfresco distribution.

  • In the SDK browse to src/web-client-src/java/org/alfresco/web/bean/workflow/StartWorkflowWizard.java

  • Replace the following lines:


  • // create a workflow package for the attached items and add them
          NodeRef workflowPackage = this.getWorkflowService().createPackage(null);

    with


          // create a workflow package for the attached items and add them
          // hmedia: if the first package item is a folder, take this folder as the workflow package
          NodeRef nodeRef = new NodeRef(this.packageItemsToAdd.get(0));
          QName type = getUnprotectedNodeService().getType(nodeRef);
          NodeRef workflowPackage;
          if (!getDictionaryService().isSubClass(type, ContentModel.TYPE_FOLDER))
             workflowPackage= this.getWorkflowService().createPackage(null);
          else {
             workflowPackage= nodeRef;
             this.packageItemsToAdd.remove(0);
          }

  • Compile the StartWorkflowWizard class.

  • Now the compiled class has to replace the one in your Alfresco distribution. Open your alfresco.war or go to the exploded alfresco folder in Tomcat. Locate the WEB-INF/lib/alfresco-web-client-x.xx.jar. Override the StartWorkflowWizard class in the jar with your StartWorkflowWizard.class.
It's so easy  Smiley Happy
After you did all this you can start an advanced workflow on a folder. In the Start Workflow Wizard you will not see the folder. This is because folders are not displayed in the workflow wizards. But as soon as you start the workflow and open the task you have assigned to a user this user will see the documents in the folder attached to the workflow.
Btw.: If you want to see the folder in the Start Workflow Wizard you would have to replace these lines of code in the StartWorkflowWizard init method:


    if (this.getDictionaryService().isSubClass(type, ContentModel.TYPE_CONTENT) ||
             this.getDictionaryService().isSubClass(type, ApplicationModel.TYPE_FILELINK))
         {
            this.packageItemsToAdd.add(itemToWorkflow.toString());
         }

with these


    // hmedia: added folder as content type
    if (this.getDictionaryService().isSubClass(type, ContentModel.TYPE_CONTENT) ||
             this.getDictionaryService().isSubClass(type, ApplicationModel.TYPE_FILELINK) ||
             this.getDictionaryService().isSubClass(type, ContentModel.TYPE_FOLDER))
         {
            this.packageItemsToAdd.add(itemToWorkflow.toString());
         }

Good luck.

hyperation
Champ on-the-rise
Champ on-the-rise
Thank you for the thorough response, I will try it out.

I would have thought this would be something that is out of the box from Alfresco. 😕

Thanks
Smiley Happy

sebp
Champ in-the-making
Champ in-the-making
I had the same thought but I realized that a lot of stuff is missing when it comes to workflows and UI.
Btw.: I realized that if more than one workflow is started on the same folder then you will have error messages to delete the previous workflows. Only the latest workflow can be deleted. So you have to make sure that only one workflow can be started on the folder.

padmalaya
Champ in-the-making
Champ in-the-making
Hi Sebp,

Is there any other way out to start workflow on folders using the existing Javascript APIs, And how to deal with this repeated errors that crop in due to application of multiple workflows on a single folder??

thanks in advance
padmalaya

sebp
Champ in-the-making
Champ in-the-making
Hi,
I'm not sure about starting a workflow on a folder using the Javascript API. Could be possible. Don't know.
It turned out that the problem I had was not related to multiple workflows on a folder but to https://issues.alfresco.com/jira/browse/ALF-2764
and http://issues.alfresco.com/jira/browse/ETWOONE-306. I had two loops in my workflow and that causes Alfresco to crash if I wanted to cancel the workflow.

padmalaya
Champ in-the-making
Champ in-the-making
Hi Sebp,

Thanks for the "fast" reply, wasnt expecting though Smiley Tongue.
However, does the above solution mentioned by you work(by changing the code in jave files)??
I tried the same , but at one point I gt errors in the build , at the second try it dint reflect in the UI itself.
Kinda stuck in it!!

Thanks ,

Padmalaya

sebp
Champ in-the-making
Champ in-the-making
The solution works. We use folders as workflow packages in daily work. What are the problems you face?