cancel
Showing results for 
Search instead for 
Did you mean: 

User task forms do not map custom variables

francesco_lilli
Champ in-the-making
Champ in-the-making
Hi,

I am new to Activiti.
I am developing my first workflow, and the flow just work as a charm, but I am stuck with an apparently stupid problem.

First I want to set execution variables into the ScriptExecutionListener of the "start" event:


<?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: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="signatureCycle" name="Signature Cycle" isExecutable="true">
     ………….
     <startEvent id="start" name="Start" activiti:formKey="wf:signatureCycle">
   <extensionElements>
      <activiti:executionListener event="start" class="org.alfresco.repo.workflow.activiti.listener.ScriptExecutionListener">
              <activiti:field name="script">
                 <activiti:string>
         execution.setVariable('wf_sect', 'AAA');
         execution.setVariable('wf_dt', 'BBB');
       </activiti:string>
              </activiti:field>
           </activiti:executionListener>
       </extensionElements>
     </startEvent>
     ………….
</definitions>


Now I want to see the values I just set into the corresponding form label fields (i.e., "AAA" into "wf:sect", and "BBB" into "wf:dt"). This is (part of) the workflow model configuration:


<?xml version="1.0" encoding="UTF-8"?>
<model name="wf:workflowmodel" xmlns="http://www.alfresco.org/model/dictionary/1.0">
   <imports>
      <import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
      <import uri="http://www.alfresco.org/model/bpm/1.0" prefix="bpm"/>
   </imports>
   <namespaces>
      <namespace uri="http://www.alfresco.org/model/workflow/1.0" prefix="wf"/>
   </namespaces>
   <types>
      …….
      <type name="wf:signatureCycle">
      <parent>bpm:startTask</parent>
      <mandatory-aspects>
         <aspect>wf:docInfo</aspect>
      </mandatory-aspects>
     </type>
     …….
   </types>
   <aspects>
      ……..
      <aspect name="wf:docInfo">
      <properties>
         <property name="wf:sect">
            <type>d:text</type>
            <mandatory>true</mandatory>
         </property>
         <property name="wf:dt">
            <type>d:text</type>
            <mandatory>true</mandatory>
         </property>
      </properties>
      </aspect>
      …..
    </aspects>
</model>


And this is (part of) the share workflow form configuration:


<alfresco-config>
    <config evaluator="string-compare" condition="activiti$signatureCycle">
      <forms>
         <form>
            <field-visibility>
               <show id="bpm:workflowDescription" />
               <show id="bpm:workflowDueDate" />
               <show id="bpm:workflowPriority" />
               <show id="wf:sect" />
               <show id="wf:dt" />
               <show id="bpm:comment" />
            </field-visibility>
            <appearance>
               <set id="" appearance="title" label-id="workflow.set.general" />
               <set id="abs" appearance="title" label-id="workflow.set.abs" />
               <field id="bpm:workflowDescription" label-id="workflow.field.message">
                  <control template="/org/alfresco/components/form/controls/textarea.ftl">
                     <control-param name="style">width: 60%</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="wf:sect" set="abs">
                  <control template="/org/alfresco/components/form/controls/info.ftl" />
               </field>
               <field id="wf:dt" set="abs">
                  <control template="/org/alfresco/components/form/controls/info.ftl" />
               </field>
               <field id="bpm:comment" label-id="workflow.field.comment"
                  set="response">
                  <control template="/org/alfresco/components/form/controls/textarea.ftl" />
               </field>
            </appearance>
         </form>
      </forms>
   </config>
</alfresco-config>


I can't see the values into the form, but I know they are actually stored. I tried to get the values as input from the form (transforming the labels into input fields), everything works just fine as the variables are stored. In fact, if I do:

<javascript>
logger.log(execution.getVariable('wf_sect'));
logger.log(execution.getVariable('wf_dt'));

</javascript>

the logs show the right values (i.e., "AAA" and "BBB" respectively), both setting them hard-coding and from user input. The only problem is that in the form I see:

<blockcode>
wf:sect: (None)
wf:dt: (None)
</blockcode>

I also tried to set values into an executionListener of the process itself, instead of in the executionListener of the start task: any form just won't show anything, just those annoying None's.
Oddly enough, though, the "Workflow Details" view shows those values without problems (even though it seems to me that once set for the first time they never change, even after resetting the variables programmatically with execution.setVariable('wf_sect', 'NEWVALUE1') and execution.setVariable('wf_dt', 'NEWVALUE2')).
Any suggestions?
11 REPLIES 11

francesco_lilli
Champ in-the-making
Champ in-the-making
Seems legit. Thanks a lot for your explanation, Frederik *i-m_so_happy*
And thank you all for your time!

*bye*

Francesco

frederikherema1
Star Contributor
Star Contributor
We are aware that the (long-time existing) WorklfowService api in Alfresco and related screens do not fully expose the activity potential, but we're working on improving this in the future…