Inside a listener, how can I get the value of a task field that has been set as an expression?

Hello,

Inside a listener, how can I get the value of a task field that has been set as an expression?

I have a task whose candidateGroups is equal to de following expression ${taskPropertyService.resolveCandidateGroups(execution)},

and I have a listener from where I am trying to get the value of the candidateGroups field, for each task instance that is created.

Is there any way to get the value of the expression resolved (instead of the expression itself)?

this is the code I have so far:


  @EventListener
  public void onExecutionEvent(ExecutionEntity executionEntity) {

    final String activityId = executionEntity.getActivityId();

    final String eventName = executionEntity.getEventName();
    final boolean isStartEvent = "start".equals(eventName);
    final boolean isUserTask =
        executionEntity.getActivity().getActivityBehavior() instanceof UserTaskActivityBehavior;

    if (isStartEvent && isUserTask) {

      UserTaskActivityBehavior userTaskActivityBehavior = (UserTaskActivityBehavior) executionEntity.getActivity().getActivityBehavior();
      String candidateGroups = userTaskActivityBehavior.
              getTaskDecorator().
              getTaskDefinition().
              getCandidateGroupIdExpressions().
              iterator().
              next().
              getExpressionText(); 
    
    //candidateGroups = ${taskPropertyService.resolveCandidateGroups(execution)}

...

I am using SpringBoot

Thank you

Hi @antmendoza,

Did you try to access it from within a task listener configured on create event?
I believe that at this point, the expression is supposed to be already evaluated.

You can access it using below snip
delegateTask.getCandidates()

https://docs.camunda.org/javadoc/camunda-bpm-platform/7.17/org/camunda/bpm/engine/delegate/DelegateTask.html#getCandidates()

Hi @hassang

thank you!!! that is exactly what I was looking for.

1 Like