Options Source with a Job Worker in Java

Hey,

I have a issue with the Options Source and find this topic Forms with modeler - calendar or additional javascript, select options from backend.

The issue is similar to my problem, but not the same. I use Java and in Camunda Platform 7 it was possible to specify the values of the Select dynamically. Similar to the topic what I found. In this Topic was answered that this comes in October, is already possible?

If it possible, how can I create the options for the Select in Java and how do I link them?

Hope someone can help me.

Have a nice day, JGS

Hey again,

last week was an update. In the current version with Camunda Platform 8.1 and with the Camunda Modeler 5.4.1 is the Options Source possible.

The question is still relevant:

Have a nice day, JGS

Hey again,

I have found a solution for me.

To do this, I created the Option class, which has the label and value fields, as described in Input data driven by process data:

public class Option<T> {
    private final String label;
    private final T value;

    public Option(String label, T value) {
        this.label = label;
        this.value = value;
    }

    public String getLabel() {
        return label;
    }

    public T getValue() {
        return value;
    }
}

I created a list of Option, add the list in the variables and works.

@ZeebeWorker(type = "load-data", autoComplete = true)
public Map<String, Object> loadData(final ActivatedJob job) {                
     final List<Option<Integer>> data = new ArrayList<>();
     data.add(new Option<>("A", 1));
     data.add(new Option<>("B", 2));
     data.add(new Option<>("C", 3));

      HashMap<String, Object> variables = new HashMap<>();
      variables.put("data", data);
      return variables;
}

My component look in JSON like this:

{
  "label": "Data",
  "type": "select",
  "id": "Field_0i8ufcq",
  "key": "item",
  "valuesKey": "data",
}

Have a nice day, JGS

3 Likes

Thanks a lot for posting the solution you found :slight_smile:

1 Like