cancel
Showing results for 
Search instead for 
Did you mean: 

[SOLVED] Possible to set the document type from a workflow?

mcook
Champ in-the-making
Champ in-the-making
Basically, I want to be able to start a custom workflow and as the first step the user will need to specify the document type from the list of available types.

Is there a way to do this / re-use the specialize type action or will I have to customize every aspect of this?
2 REPLIES 2

singleton
Champ in-the-making
Champ in-the-making
Your workflow will probably be bound to a document, this document is retrievable by:
bpm_package.children[0];

to have its doctype set, just made it some task:
<task name="custom_wf:intake" swimlane="specializedUserPool">
         <event type="task-create">
           <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>   
var doc = bpm_package.children[0];
doc.specializeType("your_model:specialized_document_type");
                                </script>
           </action>        
               </event>
</task>

mcook
Champ in-the-making
Champ in-the-making
Thank you for you reply… However, I have actually figured out a similar method using java.  The specialize type method used in javascript is not ideal for us because It can only descend down the type hierarchy.  I needed a method to set the type of the document, no matter what the original type was.  Here is what I did:

…   <super-state name="specify-document-data">      <task-node name="set-document-type">         <task name="blfinwf:setDocumentTypeTask" swimlane="initiator">            <description>Set Document Type</description>                        <event type="task-end">               <action class="com.burris.common.bpm.actions.ForceChangeTypeAction" />            </event>                        <controller>               <variable name="blfinwf_documentType" />            </controller>         </task>                  <transition name="Submit" to="set-meta-data"></transition>      </task-node>…‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

…      <type name="blfinwf:setDocumentTypeTask">         <parent>bpm:workflowTask</parent>                  <properties>            <property name="blfinwf:documentType">               <type>d:text</type>               <mandatory>true</mandatory>               <multiple>false</multiple>                              <constraints>                  <constraint type="LIST">                     <parameter name="allowedValues">                        <list>                           <value>blfin:certificateOfLiabilityInsurance</value>                           <value>blfin:1099</value>                           <value>blfin:w9</value>                        </list>                     </parameter>                  </constraint>               </constraints>            </property>         </properties>      </type>…‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

…package com.burris.common.bpm.actions;import java.util.List;import org.alfresco.repo.workflow.jbpm.JBPMNode;import org.alfresco.repo.workflow.jbpm.JBPMSpringActionHandler;import org.alfresco.service.cmr.repository.ChildAssociationRef;import org.alfresco.service.cmr.repository.NodeRef;import org.alfresco.service.cmr.repository.NodeService;import org.alfresco.service.namespace.NamespaceService;import org.alfresco.service.namespace.QName;import org.apache.log4j.Logger;import org.jbpm.context.exe.ContextInstance;import org.jbpm.graph.exe.ExecutionContext;import org.jbpm.taskmgmt.exe.TaskInstance;import org.springframework.beans.factory.BeanFactory;@SuppressWarnings("serial")public class ForceChangeTypeAction extends JBPMSpringActionHandler {   private static final Logger log = Logger.getLogger( ForceChangeTypeAction.class );      private NodeService nodeService;   private NamespaceService namespaceService;      @Override   protected void initialiseHandler( BeanFactory factory ) {            this.nodeService = (NodeService) factory.getBean( "nodeService" );      this.namespaceService = (NamespaceService) factory.getBean( "namespaceService" );   }      @Override   public void execute( ExecutionContext context ) throws Exception {            ContextInstance contextInstance = context.getContextInstance();            Object object = contextInstance.getVariable( "bpm_package" );      if ( object == null ) {                  log.fatal( "bpm_package variable is null." );         return;      }            NodeRef nodeRef = ((JBPMNode) object).getNodeRef();      if ( nodeRef == null ) {                  log.fatal( "nodeRef is null." );         return;      }            TaskInstance task = context.getTaskInstance();      String documentType = (String) task.getVariable( "blfinwf_documentType" );            QName qname = QName.createQName( documentType, namespaceService );            // Set document to finance doc type to ensure child type compatibility      // (ie someone dropped a document with a type already specified)      List<ChildAssociationRef> children = nodeService.getChildAssocs( nodeRef );      for ( ChildAssociationRef child : children ) {                  NodeRef childNodeRef = child.getChildRef();         nodeService.setType( childNodeRef, qname );      }   }}…‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Hope this helps out any other that come across something similar.