how to set a variable in startevent in alfresco?

1.7k views Asked by At

I want to get the property value mcwf:status from the model in startevent. Then I need to pass the value of mcwf:status to other forms.

Below is the code, it is not printing variable, it seems that the part of extensionElement has not been run?

The snippet of the bpmn diagram:

<startEvent id="startevent1" name="Start" activiti:formKey="mcwf:submitReviewTask">
    <extensionElements>
        <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string><![CDATA[
                        var newstatus = task.getVariableLocal('mcwf_status');
                        execution.setVariable('mcwf_newstatus', newstatus);
                        logger.log("AAAAAAAAA      " + newstatus);
                    ]]></activiti:string>
          </activiti:field>
        </activiti:taskListener>
      </extensionElements>
    </startEvent>

The snippet of the model file:

<aspect name="mcwf:status">
            <title>Status</title>
            <properties>
                <property name="mcwf:status">
                    <title>Status</title>
                    <type>d:text</type>
                    <default>0</default>
                    <constraints>
                        <constraint type="LIST">
                          <parameter name="allowedValues">
                            <list>
                            <value>100</value>
                            <value>200</value>
                            </list>
                          </parameter>
                        </constraint>
                    </constraints>
                </property>
            </properties>
        </aspect>

If I change the startevent to usertask, then I copy the code of extensionElements and paste instead of it, and don't know why it can be work properly.

1

There are 1 answers

1
Krutik Jayswal On BEST ANSWER

Below is the code snippet which is working for me for using variable in next task.

 <startEvent id="startevent2" name="Start" activiti:initiator="${initiator.properties.userName}" activiti:formKey="aw:TransportManager">
      <extensionElements>
        <activiti:executionListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string>
            <![CDATA[
              execution.setVariable('aw_vehicle_number',                                                       task.getVariable('aw_vehicle_number'));
              execution.setVariable('aw_reg_number', task.getVariable('aw_reg_number'));
              execution.setVariable('bpm_workflowDescription', task.getVariable('bpm_workflowDescription'));             
              execution.setVariable('aw_finance_comments',task.getVariable('bpm_comment'));
           ]]></activiti:string>
          </activiti:field>
         </activiti:executionListener>
     </extensionElements>
</startEvent>

Change activiti:taskListener to activiti:executionListener.