AnsweredAssumed Answered

Initiate a workflow from datalist entry

Question asked by azaharizaman on Jul 8, 2014
Hi there,

I wanted to start a custom workflow out of a datalist node. My custom datalist has a cm:person associations that defined who the person responsible (assigned) for the datalist items and the datalist items have attachments to it.

I want to make it as such, when I create a new datalist item, assigned a person to it and attach files to it. Now I want to start a workflow from this with assigned person will be the one who will have to respond to the workflow, and the attachments got attached together with the workflow.

I am customizing upon the sample from alfresco-sdk example of StartReviewWorkflowActionExecutor.java. And here is my code.


protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {

        // Lookup the assignee association of the datalist
        // The workflow will be assigned to this user
        QName PROP_QNAME_NDW_ASSIGNEE = QName.createQName("ndwDataList.model", "ndwAssignee");
   
        List<ChildAssociationRef> assignee = nodeService.getChildAssocs(actionedUponNodeRef);
        for (ChildAssociationRef childAssoca : assignee) {
            NodeRef childNodeRef = childAssoca.getChildRef();
           
            String creator = (String) nodeService.getProperty(childNodeRef, ContentModel.PROP_USERNAME);
           
            // Check if the workflow exists
            WorkflowDefinition workflow = workflowService.getDefinitionByName(REVIEW_WORKFLOW_NAME);
            if (workflow == null) {
                logger.debug("Workflow " + REVIEW_WORKFLOW_NAME + " doesn't exist.");
                // TODO: Make error message?
                action.setParameterValue(ActionExecuterAbstractBase.PARAM_RESULT, "failure");
            }

            // Set the workflow package
            // this contains the files within the workflow
            NodeRef workflowPackage = workflowService.createPackage(null);
            ChildAssociationRef childAssoc = nodeService.getPrimaryParent(actionedUponNodeRef);
            nodeService.addChild(workflowPackage, actionedUponNodeRef, WorkflowModel.ASSOC_PACKAGE_CONTAINS, childAssoc.getQName());


            // Set the parameters for the workflow
            Map<QName, Serializable> parameters = new HashMap<QName, Serializable>();
            parameters.put(WorkflowModel.ASSOC_PACKAGE, workflowPackage);


            parameters.put(WorkflowModel.ASSOC_ASSIGNEE, personService.getPerson(creator));

            String documentName = (String) nodeService.getProperty(actionedUponNodeRef, ContentModel.PROP_NAME);

            // Add description
            parameters.put(WorkflowModel.PROP_WORKFLOW_DESCRIPTION, "Review the document: " + documentName);

            WorkflowPath workflowPath = workflowService.startWorkflow(workflow.getId(), parameters);
            action.setParameterValue(ActionExecuterAbstractBase.PARAM_RESULT, "success");
           
        }
    }



Here I copied part of my custom datalist model definitions.


<model name="ndw:ndwDatalist" xmlns="http://www.alfresco.org/model/dictionary/1.0">

   <!– Optional meta-data about the model –>  
   <description>Pelita Registry Datalist</description>
   <author>Azahari Zaman</author>
   <version>1.0</version>

   <!– Imports are required to allow references to definitions in other models –>  
   <imports>
        <!– Import Alfresco Dictionary Definitions –>
      <import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
      <!– Import Alfresco Content Domain Model Definitions –>
      <import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"/>
     <!– Import Alfresco Data List Model Definitions –>
      <import uri="http://www.alfresco.org/model/datalist/1.0" prefix="dl"/>
   </imports>

   <!– Introduction of new namespaces defined by this model –>  
   <namespaces>
       <namespace uri="ndw.com" prefix="ndw"/>
   </namespaces>


   <!–      T Y P E   D E F I N I T I O N S      –>  
   <types>
     <!–   Data list defintions For this model go here –>
      <type name="ndw:registryDatalist">
       <title>Registry Datalist</title>
       <description>Registry Datalist</description>
       <parent>dl:dataListItem</parent>
       <properties>
         <property name="ndw:ndwID">
            <title>ID Number</title>
            <type>d:int</type>
            <mandatory>true</mandatory>
         </property>
         <property name="ndw:ndwReceivedDate">
            <title>Document Received Date</title>
            <type>d:datetime</type>
            <mandatory>true</mandatory>
         </property>
         <property name="ndw:ndwDocumentDate">
            <title>Document Date</title>
            <type>d:datetime</type>
            <mandatory>false</mandatory>
         </property>
         <property name="ndw:ndwSubject">
            <title>Subject</title>
            <type>d:text</type>
            <mandatory>false</mandatory>
         </property>
         <property name="ndw:ndwSenderName">
            <title>Sender Name</title>
            <type>d:text</type>
            <mandatory>false</mandatory>
         </property>
         <property name="ndw:ndwSenderAddress">
            <title>Sender Address</title>
            <type>d:text</type>
            <mandatory>false</mandatory>
         </property>
         <property name="ndw:ndwSenderRefNo">
            <title>Sender Reference Number</title>
            <type>d:text</type>
            <mandatory>false</mandatory>
         </property>
                        <property name="ndw:ndwPelitaRefNo">
            <title>Pelita Reference Number</title>
            <type>d:text</type>
            <mandatory>false</mandatory>
         </property>
                        <property name="ndw:ndwRemarks">
            <title>Remarks</title>
            <type>d:text</type>
            <mandatory>false</mandatory>
         </property>
      </properties>      

       <associations>
                        <association name="ndw:ndwAssignee">
                        <title>Acknowledge By</title>
                        <source>
                              <mandatory>false</mandatory>
                              <many>true</many>
                        </source>
                        <target>
                              <class>cm:person</class>
                              <mandatory>false</mandatory>
                              <many>false</many>
                        </target>
                 </association>
         <association name="ndw:ndwAttachments">
            <title>Attachements</title>
            <source>
              <mandatory>false</mandatory>
              <many>true</many>
            </source>
            <target>
              <class>cm:content</class>
              <mandatory>false</mandatory>
              <many>true</many>
            </target>
         </association>
       </associations>
     </type>
   </types>    
</model>


I then attached this workflow to folder rule action so that the workflow get started for every new datalist items created.

The problem is, the workflow did not start. I suspect the cm:person is null when trying to pull it out from my datalist association, but I don't know is it true or not.

Forgive my newbie question and thanks a lot for any feedback

Outcomes