cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to use custom outcomes in process

sart
Champ in-the-making
Champ in-the-making
Hi,

Clarification is needed on how to use Form's custom outcomes with Exclusive Gateway
<!–break–>
I'm trying to create the simple process with UserTask followed by Exclusive Gateway and 2 other UserTasks depended on its condition.
I've created two custom outcomes for the first UserTask: Agree and Disagree.
But I cannot find the right way to set flow conditions for Exclusive Gateway.
${outcome == "Agree"}‍
doesn't work…

Please help,

Regards

13 REPLIES 13

sart
Champ in-the-making
Champ in-the-making
The error is:
<blockcode>
org.activiti.engine.ActivitiException: Unknown property used in expression: ${outcome == "Agree"}] with root cause
org.activiti.engine.impl.javax.el.PropertyNotFoundException: Cannot resolve identifier 'outcome'
at org.activiti.engine.impl.juel.AstIdentifier.eval(AstIdentifier.java:81)
at org.activiti.engine.impl.juel.AstBinary$SimpleOperator.eval(AstBinary.java:27)
at org.activiti.engine.impl.juel.AstBinary.eval(AstBinary.java:192)
at org.activiti.engine.impl.juel.AstEval.eval(AstEval.java:49)
at org.activiti.engine.impl.juel.AstNode.getValue(AstNode.java:25)
</blockcode>

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi,

'outcome' identifier does not exist in the execution.
Could you create jUnit test please?

https://forums.activiti.org/content/sticky-how-write-unit-test

Regards
Martin

sart
Champ in-the-making
Champ in-the-making
Hi Martin,
I've created jUnit test but it passes successfully because the 'outcome' needs to be created from Activiti 6 UI reference form and I don't know how to create JUnit test that could produce the same case environment…
I posted full details here: https://activiti.atlassian.net/browse/ACT-4114
BR, Sergey

sart
Champ in-the-making
Champ in-the-making
I've workaround for this problem by using custom Spring bean:
<code>
public boolean checkOutcomeVar(String taskName, String outcome, DelegateExecution delegateExecution) {
  Boolean result = false;
  ProcessInstance process = runtimeService.createProcessInstanceQuery()
    .processInstanceId(delegateExecution.getProcessInstanceId()).singleResult();
  Task task = taskService.createTaskQuery().processInstanceId(process.getId()).taskName(taskName).singleResult();
  if (task == null) {
   throw new FormValidationException("Task '" + taskName + "' was not found");
  }
  Form form = formProcessingService.getTaskForm(task.getId());
  String formNNoutcome = "form" + Long.toString(form.getId()) + "outcome";
  String outcomeResult = (String) delegateExecution.getVariable(formNNoutcome);
  if (outcomeResult.equals(outcome)) {
   result = true;
  }
  return result;
}
</code>


Now the flow condition is:

<java>${outcomeBean.checkOutcomeVar("UserTask1", "Agree", execution)}</java>

full code is here https://github.com/sarthome/activiti-sa-extensions/blob/master/src/main/java/com/activiti/extension/...

maudrid
Champ on-the-rise
Champ on-the-rise
I found that the outcome is saved in the process variables, it is just not called outcome.
It is called "from<form_id>outcome" for example ''form1004outcome''.
So you should be able to do something like "${form1004outcome == "Agree"}"

sart
Champ in-the-making
Champ in-the-making
Hi Maudrid,

No, you can't. Because 1004 is process instance dependent number. And you have to identify it dynamically.
So I had to do it via spring bean.

Regards

maudrid
Champ on-the-rise
Champ on-the-rise
I've looked into this and you are right that the ID is not the form id.
But you are wrong in that the ID is not tied to the instance, it is tied to the deployment.
This means that you do have to dynamically get the id.
I tried to do this in a script, but I cant get access to the FormProcessingService.

maudrid
Champ on-the-rise
Champ on-the-rise
I have this working now without needing a custom java bean.
In the task, I create a TaskListener on complete:
Class: org.activiti.engine.impl.bpmn.listener.ScriptTaskListener
Param1 name: language
Param1 string value: javascript
Param2 name: script
Param2 string:
<code>
var formKey = formService.getTaskFormKey(task.getProcessDefinitionId(), task.getTaskDefinitionKey());
var execution = task.getExecution();
var outcome = execution.getVariable('form'+formKey+'outcome');
</code>

martin_grofcik
Confirmed Champ
Confirmed Champ
The strange thing is that variable is saved as
formPrefix+formKey+name
The name should be static from my point of view.

Regards
Martin