Alfresco: Display form in other model

821 Views Asked by At

I have created a workflow in Alfresco, with the following process:

Workflow diagram

  • The workflow initiator fills out a form
  • Management is assigned to review the form
  • If there are errors, it is kicked back to the initiator to update and revise
  • Otherwise, the form is approved and the workflow is complete

My issue is with the review model. It currently looks like the following:

Review model

Although it is the next step in the process, the reviewer has no reference to the form information without going back and selecting the "View Workflow" button. On that page a static version of the form is displayed, with all the information.

Is there a way to:

  1. Display a static copy of the form within the review model?
  2. Display a static copy of the form before the review model?

Here is an excerpt of the static form in the "View Workflow" area I am referring to, and would like to display:

Exerpt

2

There are 2 best solutions below

0
On BEST ANSWER

Many thanks for Krutik for his answer. Below is my full explanation on how I was able to get it to work.

Summary

  • In your bpmn file, create a userTask that loads a duplicate of your form (duplicate meaning copy the type in your model with a different name).
  • Use the same property IDs in the model, so that the data transfers over.
  • In your share-config-custom.xml, set all controls for this model to info.ftl to get them to display without being editable.
  • To get form field information to display and update between submit and revise tasks, set execution and task variables in different userTask scripts.

To get variables to transfer between forms (say between a submit and revise form), you must do the following:

Setting Variables (initial form)

In your .bpmn file, create a task listener on the event where the user first enters data into the form. For example, if you have the form at the start of the workflow, you would use the following:

<activiti:taskListener event="start" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">

Or, if you have the first form at a later userTask, change "start" to "create" and place it under that one. Under this listener, you will add a script with different sets:

if (typeof identifier_variableName != 'undefined') task.setVariableLocal('identifier_propertyName', identifier_propertyName);

The if checks to see if you are revisiting this form after an initial submission to revise fields. The first time around, all of your variables will be undefined, so no action will be taken. This allows you to reuse your form without defining yet another model.

identifier_variableName is a name you give the exection variable, and identifier_property is the name for the property you wish to save.

For example, if in your model you have a d:text property in your model called someCo:textBox, you would use:

if (typeof someCo_textBox != 'undefined') task.setVariableLocal('someCo_textBox', someCo_textBox);

Resetting Variables (review and revision forms)

As I explained at the start of this answer, creating a duplicate model with the same property names will load in the data from the first form submission. But in order for the revision form to update the data, the variables must be set again.

In your userTask that loads the duplicate form, create a task listener with event="complete". Then, for each variable your defined in the first form, you'll use execution.setVariable like the following:

execution.setVariable("someCo_textBox", task.getVariableLocal("someCo_textBox"));

This updates the execution variable so that when the first form is loaded again, the if statement will be true (as someCo_textBox won't be undefined anymore), and the updated property will display.

If you want to transfer a message between the review and revision forms, simply add a new property to the review and revise models, and add it's respective variable sets.

Code Examples

Unless you completely understood every excerpt of the process I've outlined above, I'm sure you have questions. So, here is a fuller-fledged code example:

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <process id="formWorkflow" isExecutable="true">
    <startEvent id="start" activiti:initiator="initiatorUserName" activiti:formKey="formWorkflow:start"></startEvent>
    <sequenceFlow id="sequenceFlow1" sourceRef="start" targetRef="userTask1"></sequenceFlow>
    <userTask id="userTask1" name="Review Submission" activiti:candidateGroups="GROUPS_REVIEW_GROUP" activiti:formKey="formWorkflow:reviewSubmission">
      <extensionElements>
  <activiti:taskListener event="start" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string><![CDATA[if (typeof formWorkflow_textField != 'undefined') task.setVariableLocal('formWorkflow_textField', formWorkflow_textField);]]></activiti:string>
          </activiti:field>
        </activiti:taskListener>        
  <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string><![CDATA[if (typeof task.getVariableLocal('formWorkflow_approveRejectOutcome') != undefined) execution.setVariable('formWorkflow_approveRejectOutcome', task.getVariableLocal('formWorkflow_approveRejectOutcome'));
            if (typeof task.getVariableLocal('bpm_comment') != 'undefined') execution.setVariable('bpm_comment', task.getVariableLocal('bpm_comment'));
   execution.setVariable("formWorkflow_commentBox", task.getVariableLocal("formWorkflow_commentBox"));
   execution.setVariable('bpm_comment', task.getVariableLocal("formWorkflow_commentBox"));]]></activiti:string>
          </activiti:field>
        </activiti:taskListener>
      </extensionElements>
    </userTask>
    <exclusiveGateway id="exclusiveGateway1"></exclusiveGateway>
    <userTask id="userTask2" name="Revise Submission" activiti:assignee="${initiator.properties.userName}" activiti:formKey="formWorkflow:reviseSubmission">
      <extensionElements>
        <activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string><![CDATA[if (typeof bpm_workflowDueDate != 'undefined') task.dueDate = bpm_workflowDueDate;
if (typeof bpm_workflowPriority != 'undefined') task.priority = bpm_workflowPriority;
if (typeof formWorkflow_commentBox != 'undefined') task.setVariableLocal('formWorkflow_commentBox', formWorkflow_commentBox);]]></activiti:string>
          </activiti:field>
        </activiti:taskListener>
        <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
   <activiti:field name="script">
    <activiti:string><![CDATA[execution.setVariable("formWorkflow_textField", task.getVariableLocal("formWorkflow_textField"));]]></activiti:string>
   </activiti:field>
        </activiti:taskListener>
      </extensionElements>
    </userTask>
    <sequenceFlow id="sequenceFlow4" name="Revise if rejected" sourceRef="exclusiveGateway1" targetRef="userTask2">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${formWorkflow_approveRejectOutcome == "Requires Revision"}]]></conditionExpression>
    </sequenceFlow>
    <endEvent id="end"></endEvent>
    <sequenceFlow id="flow1" sourceRef="userTask1" targetRef="exclusiveGateway1"></sequenceFlow>
    <sequenceFlow id="flow2" sourceRef="exclusiveGateway1" targetRef="end"></sequenceFlow>
    <sequenceFlow id="flow3" sourceRef="userTask2" targetRef="userTask1"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_formWorkflow">
    <bpmndi:BPMNPlane bpmnElement="formWorkflow" id="BPMNPlane_formWorkflow">
      <bpmndi:BPMNShape bpmnElement="start" id="BPMNShape_start">
        <omgdc:Bounds height="35.0" width="35.0" x="120.0" y="13.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="userTask1" id="BPMNShape_userTask1">
        <omgdc:Bounds height="60.0" width="100.0" x="220.0" y="1.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="exclusiveGateway1" id="BPMNShape_exclusiveGateway1">
        <omgdc:Bounds height="40.0" width="40.0" x="380.0" y="10.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="userTask2" id="BPMNShape_userTask2">
        <omgdc:Bounds height="60.0" width="100.0" x="351.0" y="110.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="end" id="BPMNShape_end">
        <omgdc:Bounds height="35.0" width="35.0" x="509.0" y="13.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="sequenceFlow1" id="BPMNEdge_sequenceFlow1">
        <omgdi:waypoint x="155.0" y="30.0"></omgdi:waypoint>
        <omgdi:waypoint x="220.0" y="31.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sequenceFlow4" id="BPMNEdge_sequenceFlow4">
        <omgdi:waypoint x="400.0" y="50.0"></omgdi:waypoint>
        <omgdi:waypoint x="401.0" y="110.0"></omgdi:waypoint>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="14.0" width="100.0" x="410.0" y="49.0"></omgdc:Bounds>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
        <omgdi:waypoint x="320.0" y="31.0"></omgdi:waypoint>
        <omgdi:waypoint x="380.0" y="30.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
        <omgdi:waypoint x="420.0" y="30.0"></omgdi:waypoint>
        <omgdi:waypoint x="509.0" y="30.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
        <omgdi:waypoint x="351.0" y="140.0"></omgdi:waypoint>
        <omgdi:waypoint x="270.0" y="140.0"></omgdi:waypoint>
        <omgdi:waypoint x="270.0" y="61.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

1
On

If you want to pass previous model value to next task in workflow, you need to set each value in variable using below.

execution.setVariable("varName",value);

and you can get value by below command.

execution.getVariable("varName");

below link can be use full. Alfresco task listener variables.

There is one more way of achieving this.

Image which you have added in question on last , on that page there will be one rest API which will be getting called.You can use that for getting data. and displaying it on next form.On that rest api ,you need may need to pass task details and workflow details.May be id of them.