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
Anyone? *help*
I can't seem to figure out why this happens, but it's something I need to solve before going on with programming.. I have the impression that I'm missing something as a poor newbie *cray2*

trademak
Star Contributor
Star Contributor
Just to be sure if I understand what you are doing exactly. You want to show these values on the start form of your process definition? That's not possible. You can only work with variables after the process instance has been started and that's not the case in the start form, because there's no process instance yet.

Best regards,

Hi Tijs,
thanks for your reply.

Exactly, that's what I wanted to do.
Fine, I understand. I can accepts these values not to be shown in the START form.

Now, what I can't accept is that these values are not shown in ANY of the forms.. even though these values are actually stored (I can see them in the workflow details).

jbarrez
Star Contributor
Star Contributor
The concept of a start form is that it is used to populate the variables when starting a process instance. So far we're on the same page 🙂

I checked the xml, but can't see much wrong … did you try putting it on the 'general info' set?, just to be sure?

Hi Joram,

that doesn't seem to help.. plus, as I said, in the "General Info" view (where you can access in the Workflow Details page) I can see those values.
Can't only see them in the "Prepare" task (as well as in all the other ones).
This is what I have now ( I assured that putting my variables in "general info" only makes things worse).

<code>
<?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" xmlnsSmiley Surprisedmgdc="http://www.omg.org/spec/DD/20100524/DC" xmlnsSmiley Surprisedmgdi="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>
     <userTask id="prepareTask" name="Prepare" activiti:candidateUsers="${candidatesPrepare}" activiti:formKey="wfSmiley TonguerepareTask">
      <documentation>
          "Prepare" task.
      </documentation>
      <extensionElements>
        <activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string>
  logger.log("PREPARE TASK!");
  task.setVariable('wf_sect', execution.getVariable('wf_sect'));
  logger.log("PREPARE TASK. TASK SECTION: " + task.getVariable('wf_sect'));
  task.setVariable('wf_dt', execution.getVariable('wf_dt'));
  logger.log("PREPARE TASK. TASK DT: " + task.getVariable('wf_dt'));
     </activiti:string>
          </activiti:field>
        </activiti:taskListener>
        <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string>
  logger.log("PREPARED (complete).");
     </activiti:string>
          </activiti:field>
        </activiti:taskListener>
      </extensionElements>
    </userTask>
    ……….
</definitions>
</code>


<code>
<?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>
     <type name="wfSmiley TonguerepareTask">
  <parent>bpm:workflowTask</parent>
     </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>
</code>


<code>
<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>
        <config evaluator="task-type" condition="wfSmiley TonguerepareTask">
  <forms>
   <form>
    <field-visibility>
     <show id="bpm:workflowDescription" />
     <show id="bpm:workflowDueDate" />
     <show id="bpm:workflowPriority" />
     <show id="packageItems" />
     <show id="wf:sect" />
     <show id="wf:dt" />
     <show id="bpm:comment" />
     <show id="transitions" />
    </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="items" appearance="title" label-id="workflow.set.items" />
     <set id="abs" appearance="title" label-id="workflow.set.abs" />
     <set id="response" appearance="title" label-id="workflow.set.response" />
     <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="packageItems" set="items" read-only="true"/>
     <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>
     <field id="transitions" set="response" />
    </appearance>
   </form>
  </forms>
</config>
        ……..
</alfresco-config>
</code>

francesco_lilli
Champ in-the-making
Champ in-the-making
Can't only see them in the "Prepare" FORM (as well as in all the other ones) –> sorry.

frederikherema1
Star Contributor
Star Contributor
With you're current solution, do you see the correct "PREPARE TASK. TASK SECTION: " logging passing by, from the task-create-listener? Does your "prepare-task" also have that mandatory aspect applied (which holds the wf:sect etc)? If the aspect is not present, the task's properties won't contain those properties, even though they are present in the workflow…

With regards to the "general info" section on the workflow details-page, as Joram said, the values filled in at the start are displayed and NOT the current values in the workflow..

francesco_lilli
Champ in-the-making
Champ in-the-making
That was it! I just added the mandatory aspect to the Prepare task, now I'm able to see the values in the forms.. Thank you so much.

Anyway I'd like to get to know why this happens.
1) Why is it necessary to say that an aspect is "mandatory" even though it's just visualized on a form? I thought I had to define an aspect as mandatory only if it was actually mandatory to fill it in a form…
2) Why are the values in the general info section NOT the current values in the workflow?

frederikherema1
Star Contributor
Star Contributor
1) I'm not an content-modeling expert, but the mandatory-aspects section means that the aspects are ALWAYS applied to it. As the workflow-task aren't actual pieces of alfresco-content, the model is just a description of the properties that are expected, rather than a fixed representation of what the actual data in the DB is (as is the case with normal content). So I guess there is a difference between "normal" aspects (added ad-hoc) and "mandatory" aspects, which are defined in the model. For tasks, however, always use "mandatory" ones Smiley Wink

2) This is due to the nature of the WorkflowService and related screens, historically. Activiti was implemented as a layer beneath the already existing workflow-api, not exposing "variables" of the process. Rather, those screens use the start-task to display the "General Info". This is currently the way it's implemented but is not optimal… I think the idea behind is was to be more task-focused, not paying too much attention to the "runtime info" of a process but rather focus on each task, showing relevant data for the task and the workflow on the task-form.