How to populate camunda html form Select from Map passed by camunda-bpm-spring-boot-starter-external-task-client

Hi, i am listening for a topic and returning a map from camunda-bpm-spring-boot-starter-external-task-client.

@Component
@ExternalTaskSubscription("topic4Form7")
public class Topic4Form7Handler implements ExternalTaskHandler {


    @Override
    public void execute(ExternalTask externalTask, ExternalTaskService externalTaskService) {
        
		// get variables
        Integer valuefrombpmn = externalTask.getVariable("valuefrombpmn");
        Logger.getLogger("topic4Form7").log(Level.INFO, "Received variables valuefrombpmn {0}", new Object[]{valuefrombpmn});

        Map<String,Object> myResults = new HashMap<>();
        myResults.put("1", "Abc");
        myResults.put("2", "Xyz");
        myResults.put("3", "Mno");

        externalTaskService.complete(externalTask,myResults);

        Logger.getLogger("topic4Form7").log(Level.INFO, "sent variables myresults {0}", new Object[]{myResults});

    }
	
	}

Now i want to use this myResults and populate my select box of my html form.
Here is my html form -

<form role="form" name="form">
    <div class="form-group">
        <select cam-variable-name="myselection"
                cam-variable-type="String"
                class="form-control"
                multiple="multiple"
                cam-choices="myResults">
        </select>
    </div>
</form>

But select is not populated.

By loading variables in next step i can see values from myResults

Any help regarding this (to populate html form select, Or any option to populate default camunda form select from myResults )

Note : I am using camunda 7.16 with spring boot.

Thanks.

Hi,
I think for it to work you would need to serialize your variable to json format instead. I did something similar in javascript and then it looked something like:

execution.setVariable("usersForSelect",S(usersForSelect, "application/json"));

while usersForSelect was a HashMap (defined via Java.type(“java.util.HashMap”)).
Hope it helps, I would be curious to know whether it worked for your use case.

Hi @vivekkarn,

in your external task worker, you set three different process variables, with keys “1”, “2” and “3”. The variable “myResults” is not visibile in the process instance. It is just a temporary Java variable.

Hope this helps, Ingo

Hi,
@eileen
@Ingo_Richtsmeier
Now i am converting my map` to Json.
And by sending it, i am receiving it at the other end.

Map<String,Object> myDataMapToSend = new HashMap<>();
        myResultsOriginal.put("1", "Abc");
        myResultsOriginal.put("2", "Xyz");
        myResultsOriginal.put("3", "Mno");

        Gson gson = new Gson();
        String myJsonDataToSend = gson.toJson(myDataMapToSend);

        Map<String,Object> myResults = new HashMap<>();
        myResults.put("myData",myJsonDataToSend);
        externalTaskService.complete(externalTask,myResults);

But when i try to set my html form select from it (myData) it is coming up like -

Here is my html form -

<div class="form-group">
        <select cam-variable-name="myselection"
                cam-variable-type="String"
                class="form-control"
                cam-choices="myData"
                multiple="multiple">
        </select>
    </div>

Any help how to setup my select and display it properly.
Thanks