cancel
Showing results for 
Search instead for 
Did you mean: 

ScriptTask: getting process instance variable problem

partizano
Champ in-the-making
Champ in-the-making
Hi, Activiti Team!

I have problem with getting process instance variable in Script Task.

My process is:
<process id="test-proc" name="test-proc">
    <startEvent id="startevent1" name="Start"></startEvent>
    <endEvent id="endevent1" name="End"></endEvent>
    <scriptTask id="scripttask1" name="Script Task" scriptFormat="javascript">
      <script><![CDATA[var procInstVariable = execution.getVariable('procInstVariable');
]]></script>
    </scriptTask>
    <userTask id="usertask1" name="User Task" activiti:assignee="kermit"></userTask>
    <sequenceFlow id="flow2" name="" sourceRef="scripttask1" targetRef="usertask1"></sequenceFlow>
    <sequenceFlow id="flow3" name="" sourceRef="usertask1" targetRef="endevent1"></sequenceFlow>
    <sequenceFlow id="flow4" name="" sourceRef="startevent1" targetRef="scripttask1"></sequenceFlow>
  </process>

I am starting process with Java Api:
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("procInstVariable", "value1");
processEngine.getRuntimeService().startProcessInstanceByKey("test-proc", variables);

And I am getting the following error:
 org.activiti.engine.ActivitiException: coudn't deserialize value 'sun.org.mozilla.javascript.internal.NativeJavaObject@3e1c3e1c' in variable 'procInstVariable'
   at org.activiti.engine.impl.variable.SerializableType.serialize(SerializableType.java:83)
   at org.activiti.engine.impl.variable.SerializableType.setValue(SerializableType.java:68)
   at org.activiti.engine.impl.persistence.entity.VariableInstanceEntity.setValue(VariableInstanceEntity.java:164)
   at org.activiti.engine.impl.persistence.entity.VariableInstanceEntity.create(VariableInstanceEntity.java:72)
   at org.activiti.engine.impl.persistence.entity.VariableInstanceEntity.createAndInsert(VariableInstanceEntity.java:58)
   at org.activiti.engine.impl.persistence.entity.VariableScopeImpl.createVariableLocal(VariableScopeImpl.java:225)
   at org.activiti.engine.impl.persistence.entity.VariableScopeImpl.setVariableLocal(VariableScopeImpl.java:187)
   at org.activiti.engine.impl.persistence.entity.VariableScopeImpl.setVariable(VariableScopeImpl.java:167)
   at org.activiti.engine.impl.scripting.ScriptBindings.put(ScriptBindings.java:72)
   at javax.script.SimpleScriptContext.setAttribute(SimpleScriptContext.java:222)
   at com.sun.script.javascript.ExternalScriptable.put(ExternalScriptable.java:163)
   at sun.org.mozilla.javascript.internal.ScriptableObject.putProperty(ScriptableObject.java:1385)
   at sun.org.mozilla.javascript.internal.ScriptRuntime.setName(ScriptRuntime.java:1730)
   at sun.org.mozilla.javascript.internal.Interpreter.interpretLoop(Interpreter.java:2788)
   at sun.org.mozilla.javascript.internal.Interpreter.interpret(Interpreter.java:2239)
   at sun.org.mozilla.javascript.internal.InterpretedFunction.call(InterpretedFunction.java:138)
   at sun.org.mozilla.javascript.internal.ContextFactory.doTopCall(ContextFactory.java:323)
   at sun.org.mozilla.javascript.internal.ScriptRuntime.doTopCall(ScriptRuntime.java:2747)
   at sun.org.mozilla.javascript.internal.InterpretedFunction.exec(InterpretedFunction.java:149)
   at sun.org.mozilla.javascript.internal.Context.evaluateReader(Context.java:1169)
   at com.sun.script.javascript.RhinoScriptEngine.eval(RhinoScriptEngine.java:106)
   at com.sun.script.javascript.RhinoScriptEngine.eval(RhinoScriptEngine.java:124)
   at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:227)
   at org.activiti.engine.impl.scripting.ScriptingEngines.evaluate(ScriptingEngines.java:75)
   at org.activiti.engine.impl.bpmn.behavior.ScriptTaskActivityBehavior.execute(ScriptTaskActivityBehavior.java:51)
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationActivityExecute.execute(AtomicOperationActivityExecute.java:44)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:77)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:530)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:525)
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionNotifyListenerStart.eventNotificationsCompleted(AtomicOperationTransitionNotifyListenerStart.java:52)
   at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:56)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:77)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:530)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:525)
   at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:49)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:77)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:530)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:525)
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionCreateScope.execute(AtomicOperationTransitionCreateScope.java:49)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:77)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:530)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:525)
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionNotifyListenerTake.execute(AtomicOperationTransitionNotifyListenerTake.java:65)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:77)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:530)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:525)
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionDestroyScope.execute(AtomicOperationTransitionDestroyScope.java:115)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:77)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:530)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:525)
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionNotifyListenerEnd.eventNotificationsCompleted(AtomicOperationTransitionNotifyListenerEnd.java:36)
   at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:56)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:77)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:530)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:525)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.take(ExecutionEntity.java:365)
   at org.activiti.engine.impl.bpmn.behavior.BpmnActivityBehavior.performOutgoingBehavior(BpmnActivityBehavior.java:102)
   at org.activiti.engine.impl.bpmn.behavior.BpmnActivityBehavior.performDefaultOutgoingBehavior(BpmnActivityBehavior.java:51)
   at org.activiti.engine.impl.bpmn.behavior.FlowNodeActivityBehavior.leave(FlowNodeActivityBehavior.java:44)
   at org.activiti.engine.impl.bpmn.behavior.FlowNodeActivityBehavior.execute(FlowNodeActivityBehavior.java:36)
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationActivityExecute.execute(AtomicOperationActivityExecute.java:44)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:77)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:530)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:525)
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationProcessStartInitial.eventNotificationsCompleted(AtomicOperationProcessStartInitial.java:46)
   at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:56)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:77)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:530)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:525)
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationProcessStart.eventNotificationsCompleted(AtomicOperationProcessStart.java:45)
   at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:56)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:77)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:530)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:525)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.start(ExecutionEntity.java:319)
   at org.activiti.engine.impl.cmd.StartProcessInstanceCmd.execute(StartProcessInstanceCmd.java:72)
   at org.activiti.engine.impl.cmd.StartProcessInstanceCmd.execute(StartProcessInstanceCmd.java:31)
   at org.activiti.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:24)
   at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:42)
   at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:33)
   at org.activiti.engine.impl.RuntimeServiceImpl.startProcessInstanceByKey(RuntimeServiceImpl.java:54)

I will be glad for any help.
5 REPLIES 5

jbarrez
Star Contributor
Star Contributor
Our test cases all use groovy, so didn't test javascript yet.

Could you create a test project (including maven pom.xml for the javascript engine depenendencies), and create a jira issue such that we can test it?

partizano
Champ in-the-making
Champ in-the-making
Solved by this:

<script><![CDATA[var procInstVariable = execution.getVariable('procInstVariable') + '';
]]></script>

jbarrez
Star Contributor
Star Contributor
Ok, interesting….

Thanks for posting the solution!

iam
Champ in-the-making
Champ in-the-making
Hi.
I have something like this.
I have bean 'myUtil' and use it in scripTask:
n = myUtil.encode(execution, "abc");It should return a string.
When I use 'groovy' all ok, but if I use 'javascript' I have error.
Error solved if I concatenate this with blank string:
n = myUtil.encode(execution, "abc") + "";
In ScriptBindings.java in method 'put' i have value as String when use groovy.
And when use javascript the value is sun.org.mozilla.javascript.NativeJavaObject

jbarrez
Star Contributor
Star Contributor
ok, interesting.

But like I said, my knowledge of using javascript as scripting language in Activiti is limited … so I'm afraid I can't give you a decent answer there.