cancel
Showing results for 
Search instead for 
Did you mean: 

Workflow Share Form Issue

tarun27in
Champ in-the-making
Champ in-the-making
Hi,

I am trying to build a custom workflow in alfresco community edition. Basically I am trying to modify the existing workflow called lifecycleprocess. I have been able to deploy the process using workflow console without error. But I am not able to do any change at all on the workflow form. My workflow is called leaveprocess and I have the following code :-

Path : alfresco/tomcat/shared/classes/alfresco/extension/

<strong>leave-process-bpmn20.xml</strong>



<?xml version="1.0" encoding="UTF-8" ?>

<definitions id="leave-definitions"
             typeLanguage="http://www.w3.org/2001/XMLSchema"
             expressionLanguage="http://www.w3.org/1999/XPath"
             targetNamespace="http://activiti.org/bpmn20"
             xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:activiti="http://activiti.org/bpmn">

    <process id="activitileaveApproval" name="Leave Process">
        <extensionElements>
             <!– When process is deleted/cancelled, status should be set to draft –>
             <activiti:executionListener event="end" class="org.alfresco.repo.workflow.activiti.listener.ScriptExecutionListener">
                <activiti:field name="script">
                     <activiti:string>
                        if(cancelled || deleted) {
                            for (var i = 0; i &lt; bpm_package.children.length; i++)
                            {
                               if (!bpm_package.children.hasAspect("wfl:status"))
                               {
                                    bpm_package.children.properties["wfl:status"] = "Draft";
                                    bpm_package.children.save();
                               }
                            }
                        }
                     </activiti:string>
                  </activiti:field>
            </activiti:executionListener>
         </extensionElements>
        <startEvent id="start"
            activiti:formKey="wf:submitReviewTask" />

        <sequenceFlow id='flow1'
            sourceRef='start'
            targetRef='reviewTask'>
             <extensionElements>
                 <activiti:executionListener event="take" class="org.alfresco.repo.workflow.activiti.listener.ScriptExecutionListener">
                    <activiti:field name="script">
                         <activiti:string>
                            for (var i = 0; i &lt; bpm_package.children.length; i++)
                            {
                               if (!bpm_package.children.hasAspect("wfl:status"))
                               {
                                  bpm_package.children.addAspect("wfl:status");
                               }
                            }
                         </activiti:string>
                      </activiti:field>
                </activiti:executionListener>
             </extensionElements>
        </sequenceFlow>

        <userTask id="reviewTask" name="Review Task"
            activiti:formKey="wf:activitiReviewTask">
           <extensionElements>
               <activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
                  <activiti:field name="script">
                     <activiti:string>
                        if (typeof bpm_workflowDueDate != 'undefined') task.setVariableLocal('bpm_dueDate', bpm_workflowDueDate);

                         for (var i = 0; i &lt; bpm_package.children.length; i++)
                         {
                            if (bpm_package.children[0].hasAspect("wfl:status")) {
                                bpm_package.children.properties["wfl:status"] = "In Review";
                                bpm_package.children.save();
                            }
                         }
                     </activiti:string>
                  </activiti:field>
               </activiti:taskListener>
               <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
                  <activiti:field name="script">
                     <activiti:string>
                        execution.setVariable('wf_reviewOutcome', task.getVariable('wf_reviewOutcome'));
                     </activiti:string>
                  </activiti:field>
               </activiti:taskListener>
           </extensionElements>
            <humanPerformer>
                <resourceAssignmentExpression>
                    <formalExpression>${bpm_assignee.properties.userName}</formalExpression>
                </resourceAssignmentExpression>
            </humanPerformer>
        </userTask>

        <sequenceFlow id='flow2'
        sourceRef='reviewTask'
            targetRef='reviewDecision' />

        <exclusiveGateway  id="reviewDecision" name="Review Decision" />

        <sequenceFlow id='flow3' sourceRef='reviewDecision' targetRef='approved' >
            <conditionExpression xsi:type="tFormalExpression">${wf_reviewOutcome == 'Approve'}</conditionExpression>
        </sequenceFlow>

        <sequenceFlow id='flow4'
        sourceRef='reviewDecision'
            targetRef='rejected' />

       <userTask id="approved" name="Document Approved"
            activiti:formKey="wf:approvedTask" >
            <documentation>
                The document was reviewed and approved.
            </documentation>
            <extensionElements>
               <activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
                  <activiti:field name="script">
                     <activiti:string>
                        if (typeof bpm_workflowDueDate != 'undefined') task.setVariableLocal('bpm_dueDate', bpm_workflowDueDate);

                        for (var i = 0; i &lt; bpm_package.children.length; i++)
                        {
                           if (bpm_package.children[0].hasAspect("wfl:status")) {
                               bpm_package.children.properties["wfl:status"] = "Approved";
                               bpm_package.children.save();
                           }
                        }
                     </activiti:string>
                  </activiti:field>
               </activiti:taskListener>
            </extensionElements>
            <humanPerformer>
                <resourceAssignmentExpression>
                    <formalExpression>${initiator.properties.userName}</formalExpression>
                </resourceAssignmentExpression>
            </humanPerformer>
        </userTask>

        <userTask id="rejected" name="Document Rejected"
            activiti:formKey="wf:rejectedTask" >
            <documentation>
                The document was reviewed and rejected.
            </documentation>
            <extensionElements>
               <activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
                  <activiti:field name="script">
                     <activiti:string>
                        if (typeof bpm_workflowDueDate != 'undefined') task.setVariableLocal('bpm_dueDate', bpm_workflowDueDate);

                        for (var i = 0; i &lt; bpm_package.children.length; i++)
                        {
                           if (bpm_package.children[0].hasAspect("wfl:status"))
                           {
                              bpm_package.children.properties["wfl:status"] = "Draft";
                              bpm_package.children.save();
                           }
                        }
                     </activiti:string>
                  </activiti:field>
               </activiti:taskListener>
            </extensionElements>
            <humanPerformer>
                <resourceAssignmentExpression>
                    <formalExpression>${initiator.properties.userName}</formalExpression>
                </resourceAssignmentExpression>
            </humanPerformer>
        </userTask>

        <sequenceFlow id='flow5' sourceRef='approved'
            targetRef='end' />

        <sequenceFlow id='flow6' sourceRef='rejected'
            targetRef='end' />

        <endEvent id="end" />



    </process>

</definitions>



<strong>leave-messages.properties</strong>


# For JBPM leave Workflow Example
wfl_leaveapproval.workflow.title=Leave Application
wfl_leaveapproval.workflow.description=Leave Application (Auto updates document status)
wfl_leaveapproval.node.review.transition.reject.title=Reject
wfl_leaveapproval.node.review.transition.reject.description=Reject
wfl_leaveapproval.node.review.transition.approve.title=Approve
wfl_leaveapproval.node.review.transition.approve.description=Approve

# For Activiti leave Workflow Example
activitileaveApproval=Leave Application
activitileaveApproval=Leave Application workflow Activiti (Auto updates document status)



<strong>leave-workflow-context.xml</strong>

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

<beans>

    <bean id="leave.workflowBootstrap" parent="workflowDeployer">
        <property name="workflowDefinitions">
            <list>
                <!– JBPM version of leave process –>
                <props>
                    <prop key="engineId">jbpm</prop>
                    <prop key="location">alfresco/extension/leave_processdefinition.xml</prop>
                    <prop key="mimetype">text/xml</prop>
                    <prop key="redeploy">false</prop>
                </props>
                <!– Activiti version of leave process –>
                <props>
                    <prop key="engineId">activiti</prop>
                    <prop key="location">alfresco/extension/leave-process.bpmn20.xml</prop>
                    <prop key="mimetype">text/xml</prop>
                    <prop key="redeploy">false</prop>
                </props>
            </list>
        </property>
        <property name="models">
            <list>
                <value>alfresco/extension/leaveModel.xml</value>
            </list>
        </property>
        <property name="labels">
            <list>
                <value>alfresco/extension/leave-messages</value>
            </list>
        </property>
    </bean>

</beans>


<strong>leave_processdefinition.xml</strong>



<?xml version="1.0" encoding="UTF-8"?>

<process-definition xmlns="urn:jbpm.org:jpdl-3.1" name="wfl:leaveapproval">

    <swimlane name="initiator" />

    <start-state name="start">
        <task name="wf:submitReviewTask" swimlane="initiator" />

        <event type="node-leave">
            <!– Call script once the workflow package exists i.e. on node-leave –>
            <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
                <!– Apply the Workflow leave Aspect (wfl:status) if not set already. Note: The default wfl:status property is draft –>
                <script>
                    for (var i = 0; i &lt; bpm_package.children.length; i++)
                    {
                       if (!bpm_package.children.hasAspect("wfl:status"))
                       {
                          bpm_package.children.addAspect("wfl:status");
                       }
                    }
                </script>
            </action>
        </event>

        <transition name="" to="review" />
    </start-state>

    <swimlane name="reviewer">
       <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
          <actor>#{bpm_assignee}</actor>
       </assignment>
    </swimlane>

    <task-node name="review">
        <event type="node-enter">
            <!– Update the status to In Review when we enter this task –>
            <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
                <script>
                    for (var i = 0; i &lt; bpm_package.children.length; i++)
                    {
                       bpm_package.children.properties["wfl:status"] = "In Review";
                       bpm_package.children.save();
                    }
                </script>
            </action>
        </event>

        <task name="wf:reviewTask" swimlane="reviewer">
            <event type="task-create">
                <script>
                    if (bpm_workflowDueDate != void) taskInstance.dueDate = bpm_workflowDueDate;
                    if (bpm_workflowPriority != void) taskInstance.priority = bpm_workflowPriority;
                </script>
            </event>
        </task>

        <transition name="approve" to="approved" />
        <transition name="reject" to="rejected" />
    </task-node>

    <task-node name="rejected">
        <event type="node-enter">
            <!– Update the status to Draft when we enter this task –>
            <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
                <script>
                    for (var i = 0; i &lt; bpm_package.children.length; i++)
                    {
                       bpm_package.children.properties["wfl:status"] = "Draft";
                       bpm_package.children.save();
                    }
                </script>
            </action>
        </event>

        <task name="wf:rejectedTask" swimlane="initiator" />
        <transition name="" to="end" />
    </task-node>

    <task-node name="approved">
        <event type="node-enter">
            <!– Update the status to Approved when we enter this task –>
            <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
                <script>
                    for (var i = 0; i &lt; bpm_package.children.length; i++)
                    {
                       bpm_package.children.properties["wfl:status"] = "Approved";
                       bpm_package.children.save();
                    }
                </script>
            </action>
        </event>

        <task name="wf:approvedTask" swimlane="initiator" />
        <transition name="" to="end" />
    </task-node>

    <end-state name="end" />

    <event type="process-end">
        <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
                if (cancelled)
                {
                    for (var i = 0; i &lt; bpm_package.children.length; i++)
                    {
                       if (bpm_package.children[0].hasAspect("wfl:status"))
                       {
                          bpm_package.children.properties["wfl:status"] = "Draft";
                          bpm_package.children.save();
                       }
                    }
                    if (logger.isLoggingEnabled()) logger.log("Workflow cancelled, status reset to Draft");
                }
                else               
                {
                    if (logger.isLoggingEnabled()) logger.log("Workflow completed");
                }
            </script>
        </action>
    </event>

</process-definition>



<strong>leaveModel.xml</strong>


<?xml version="1.0" encoding="UTF-8"?>

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

    <!– Optional meta-data about the model –>
    <description>Workflow leave Model</description>
    <author></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" />
    </imports>

    <namespaces>
        <namespace uri="wfl.model" prefix="wfl" />
    </namespaces>

    <constraints>
        <constraint name="wfl:status" type="LIST">
            <parameter name="allowedValues">
                <list>
                    <value>Draft</value>
                    <value>In Review</value>
                    <value>Approved</value>
                </list>
            </parameter>
        </constraint>
    </constraints>

    <aspects>

        <!– Status property is used to manage workflow approval –>
        <aspect name="wfl:status">
            <title>Status</title>
            <properties>
                <property name="wfl:status">
                    <title>Status</title>
                    <type>d:text</type>
                    <default>Draft</default>
                    <constraints>
                        <constraint ref="wfl:status" />
                    </constraints>
                </property>
            </properties>
        </aspect>

    </aspects>

</model>


—————————————————
Path : alfresco/tomcat/webapps/share/WEB-INF/classes/alfresco/
<strong>share-workflow-form-config.xml</strong>


<!– Leave Workflow Definition –>
   <config evaluator="string-compare" condition="jbpm$wfl:leaveApproval">
      <forms>
         <form>
            <field-visibility>
               <show id="bpm:workflowDescription" />
               <show id="bpm:workflowDueDate" />
               <show id="bpm:workflowPriority" />
               <show id="bpm:assignee" />
               <show id="packageItems" />
               <show id="bpm:sendEMailNotifications" />
            </field-visibility>
            <appearance>
               <set id="" appearance="title" label-id="workflow.set.general" />
               <set id="info" appearance="" template="/org/alfresco/components/form/2-column-set.ftl" />
               <set id="assignee" appearance="title" label-id="workflow.set.assignee" />
               <set id="items" appearance="title" label-id="workflow.set.items" />
               <set id="other" appearance="title" label-id="workflow.set.other" />

               <field id="bpm:workflowDescription" label-id="workflow.field.message">
                  <control template="/org/alfresco/components/form/controls/textarea.ftl">
                     <control-param name="style">width: 95%</control-param>
                  </control>
               </field>
               <field id="bpm:workflowDueDate" label-id="workflow.field.due" set="info" />
               <field id="bpm:workflowPriority" label-id="workflow.field.priority" set="info">
                  <control template="/org/alfresco/components/form/controls/workflow/priority.ftl" />
               </field>
               <field id="bpm:assignee" label-id="workflow.field.reviewer" set="assignee" />
               <field id="packageItems" set="items" />
               <field id="bpm:sendEMailNotifications" set="other">
                  <control template="/org/alfresco/components/form/controls/workflow/email-notification.ftl" />
               </field>
            </appearance>
         </form>
      </forms>
   </config>

    <config evaluator="string-compare" condition="activiti$activitileaveApproval">
      <forms>
         <form>
            <field-visibility>
               <show id="bpm:workflowDescription" />
               <show id="bpm:workflowDueDate" />
               <show id="bpm:workflowPriority" />
               <show id="bpm:assignee" />
               <show id="packageItems" />
               <show id="bpm:sendEMailNotifications" />
            </field-visibility>
            <appearance>
               <set id="" appearance="title" label-id="workflow.set.general" />
               <set id="info" appearance="" template="/org/alfresco/components/form/2-column-set.ftl" />
               <set id="assignee" appearance="title" label-id="workflow.set.assignee" />
               <set id="items" appearance="title" label-id="workflow.set.items" />
               <set id="other" appearance="title" label-id="workflow.set.other" />

               <field id="bpm:workflowDescription" label-id="workflow.field.message">
                  <control template="/org/alfresco/components/form/controls/textarea.ftl">
                     <control-param name="style">width: 95%</control-param>
                  </control>
               </field>
               <field id="bpm:workflowDueDate" label-id="workflow.field.due" set="info">
                  <control template="/org/alfresco/components/form/controls/date.ftl">
                      <control-param name="showTime">false</control-param>
                      <control-param name="submitTime">false</control-param>
                  </control>
               </field>
               <field id="bpm:workflowPriority" label-id="workflow.field.priority" set="info">
                  <control template="/org/alfresco/components/form/controls/workflow/priority.ftl" />
               </field>
               <field id="bpm:assignee" label-id="workflow.field.reviewer" set="assignee" />
               <field id="packageItems" set="items" />
               <field id="bpm:sendEMailNotifications" set="other">
                  <control template="/org/alfresco/components/form/controls/workflow/email-notification.ftl" />
               </field>
            </appearance>
         </form>
      </forms>
   </config>



I am unable to understand, no matter what changes I do in this code for share-workflow-form-config.xml, It does not reflect when go to Share->Workflows I've started->select Leave Process. It always show the default form there. Somebody please guide me what I am doing wrong here.

Thanks in advance.

Regards,
Tarun

6 REPLIES 6

lyles
Champ in-the-making
Champ in-the-making
It might be okay where it is, but your custom form configuration should really go in:
alfresco/tomcat/shared/classes/alfresco/extension/share-config-custom.xml
instead of where you put it:
alfresco/tomcat/webapps/share/WEB-INF/classes/alfresco/share-workflow-form-config.xml

Also, unless you posted only a snippet from the file, you're missing the surrounding
<alfresco-config> </alfresco-config>
tags.

tarun27in
Champ in-the-making
Champ in-the-making
Sure, I understood and somehow made it working now. I am not stuck at one more task. I want to have an extra approval in between, can you guide me how to accomplish that? I want one approver to approve the request and then the task should go to second approver and then approved or rejected should notify the initiator. Thats it. I am not sure how to acheive that.

stacy
Champ on-the-rise
Champ on-the-rise
Hi,

I have requirement where in when i start a leave process workflow a customized form has to appear and not the default one. How do i achieve that ??

Any help will be appreciated. Thanks in advance.

stacy
Champ on-the-rise
Champ on-the-rise
I wanted to know if content modelling is involved here or it is just a configuration in an xml file under field visibility  and set id.

I am very new to alfresco, so coming up with these issues.

darkredd
Star Contributor
Star Contributor
Hi Stacy,

Both the task modelling and form config xml files have to be in use. In you task model, you actually define fields within each of the task that will ultimately be configured in your share-config.xml file. Your config file is there to adhere to what you defined in your model file, and perhaps to ad a few built-in fields. This wiki should help you understand more: http://wiki.alfresco.com/wiki/Forms

stacy
Champ on-the-rise
Champ on-the-rise
Hi,

Thank you for the reply and info. I am working on it .

Stacy