cancel
Showing results for 
Search instead for 
Did you mean: 

How to get who completed task?

ismail1
Champ in-the-making
Champ in-the-making
Hi folks,
in such a scenario of two user tasks one for manager approves, after that accountant approves. I would like to get at the acoountants phase which manager completed  task before… is this possible?
              

               <startEvent id="startevent1" name="Start" activiti:initiator="employee">
                …..
               </startEvent>
          <userTask id="usertask1" name="Management handle request" activiti:candidateGroups="management" >
         <documentation>${employee} has requested a refund of ${amount} Euro.
         </documentation>
         ….
      </userTask>

      <userTask id="usertask3" name="Accountancy handle request" activiti:candidateGroups="accountancy">
         <documentation>${employee} has requested a refund of ${amount}
            Euro. ${employee}'s manager has approved.
         </documentation>
      </userTask>

instead of "${employee}'s manager has approved." something like that ${manager} has approved….

Thanks….
5 REPLIES 5

frederikherema1
Star Contributor
Star Contributor
This is possible. You can use a taskListener (event=complete) to copy the approvers username to a shared process-variable. This can be done using a org.activiti.engine.impl.bpmn.listener.ScriptTaskListener, from the top of my head:


<activiti:taskListener event="complete" class="org.activiti.engine.impl.bpmn.listener.ScriptTaskListener" >
  <activiti:field name="script">
    <activiti:string>
     var approvingManager = task.assignee;
     execution.setVariable("approvingManager", approvingManager);
    </activiti:string>
  </activiti:field>
  <activiti:field name="language" stringValue="javascript" />
<activiti:taskListener>

Later on in the process the "approvingManager" variable is available to use, for example, in expressions.

ismail1
Champ in-the-making
Champ in-the-making
Thanks for quick reply…

execution and task is predefined variable right?

I get an exception that says execution is not defined…

<code>
Caused by: org.activiti.engine.ActivitiException: problem evaluating script: sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "execution" is not defined. (<Unknown source>#2) in <Unknown source> at line number 2
at org.activiti.engine.impl.scripting.ScriptingEngines.evaluate(ScriptingEngines.java:77)
at org.activiti.engine.impl.scripting.ScriptingEngines.evaluate(ScriptingEngines.java:64)
at org.activiti.engine.impl.bpmn.listener.ScriptTaskListener.notify(ScriptTaskListener.java:49)
at org.activiti.engine.impl.delegate.TaskListenerInvocation.invoke(TaskListenerInvocation.java:34)
at org.activiti.engine.impl.delegate.DelegateInvocation.proceed(DelegateInvocation.java:37)
at org.activiti.engine.impl.delegate.DefaultDelegateInterceptor.handleInvocation(DefaultDelegateInterceptor.java:25)
at org.activiti.engine.impl.bpmn.helper.ClassDelegate.notify(ClassDelegate.java:93)
… 59 more
Caused by: javax.script.ScriptException: sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "execution" is not defined. (<Unknown source>#2) in <Unknown source> at line number 2
at com.sun.script.javascript.RhinoScriptEngine.eval(RhinoScriptEngine.java:110)
at com.sun.script.javascript.RhinoScriptEngine.eval(RhinoScriptEngine.java:124)
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:216)
at org.activiti.engine.impl.scripting.ScriptingEngines.evaluate(ScriptingEngines.java:75)
… 65 more
</code>

martin_grofcik
Confirmed Champ
Confirmed Champ
code snippet from jUnit test:
https://github.com/Activiti/Activiti/blob/master/modules/activiti-engine/src/test/resources/org/acti...

    <scriptTask id="script2" scriptFormat="JavaScript">
      <script><![CDATA[
       
        var sum = a + b;          
        execution.setVariable("sum", sum);
           
        ]]></script>
    </scriptTask>

this should work.

Martin

ismail1
Champ in-the-making
Champ in-the-making
Thanks Martin, i'd prefer task listener.
Here's what i accomplished….
I changed ScriptTaskListener to ScriptExecutionListener and it didnt complain for "execution". So execution predefined can not be used in ScriptTaskListener.

I returned manager as script return variable instead of setting as execution variable.

It worked, thanks…

Heres the resulting snippet:

<code>
<activiti:taskListener event="complete" class="org.activiti.engine.impl.bpmn.listener.ScriptTaskListener">
     <activiti:field name="script">
      <activiti:string>
           var approvingManager = task.assignee;        
           approvingManager // implicit return value
         </activiti:string>
     </activiti:field>
     <activiti:field name="language" stringValue="javascript" />
     <activiti:field name="resultVariable" stringValue="approvingManager"  />
    </activiti:taskListener>
</code>

diegoarpar
Champ in-the-making
Champ in-the-making
This an example for script tag usign taskListener with class org.activiti.engine.impl.bpmn.listener.ScriptTaskListener

var consolidadoObservaciones = task.getVariable('consolidadoObservaciones');
var respuestaObservacion = task.getVariable("respuestaObservacion"); 
var assignee=task.getVariable("assignee");
if(consolidadoObservaciones==null){consolidadoObservaciones="";}  
task.setVariable("consolidadoObservaciones", consolidadoObservaciones+"-"+ assignee + " responde "+respuestaObservacion );
task.setVariable("respuestaObservacion","");