Store list of String in process varibales

I have a use case where I need to store list of String as process variables?
Can anyone guide me how to achieve this?

Thank you!

Is this from a delegate?
if so its just

List<String> aStringList = new ArrayList<>();
// add stuff to list
execution.setVariable("varName", aStringList);

This is from a User Task. I have a form from which I want to save a list of variables

@Mass_Shake are you using camunda provided task form or you’re having your own task forms and making rest api call to submit the form?

I have my own task forms and I am making ReST API calls to submit the form

Not done much with forms, but this is an example of how I’ve set variables in the past, so not sure if thats similar to how you are doing it

<form role="form" class="form-horizontal">

    <script cam-script type="text/form-script">
    var variableManager = camForm.variableManager;
    var fullJsonField = $('#fullJson', camForm.formElement);

    camForm.on('form-loaded', function() {
      variableManager.fetchVariable('jsonMessage');
    });

    camForm.on('variables-fetched', function() {
      fullJsonField.val(JSON.stringify(camForm.variableManager.variableValue('jsonMessage')));
    });

    camForm.on('submit', function(evt) {
      var fieldValue = fullJsonField.val();
      // set value in variable manager so that it can be sent to backend
      variableManager.variableValue('jsonMessage', JSON.parse(fieldValue));
    });
  </script>

    <div class="control-group">
        <label class="control-label" for="fullJson">full json</label>
        <div class="controls">
            <textarea id="fullJson" type="text" class="form-control" required ></textarea>
        </div>
    </div>

</form>

Thanks for the input @matt ,but currently I am not doing like this.maybe in future I’ll try this

@Mass_Shake you need to send the list as serialized data via rest api. You can use Jackson ObjectMapper or Google Gson to serialize the data.

In ValueInfo, you need to set below values for serialized data.

objectTypeName --> java.util.ArrayList
serializationDataFormat --> application/json

image

Refer the below example which has a serialized list of data: (check: services variable)

{
    "businessKey": "test-002434",
    "withVariablesInReturn": true,
    "variables": {
        "services": {
            "type": "Object",
            "value": "[\"checkcredit\",\"validatecredit\"]",
            "valueInfo": {
                "objectTypeName": "java.util.ArrayList",
                "serializationDataFormat":"application/json"
            }
        },
        "requestMethod": {
            "type": "String",
            "value": "POST",
            "valueInfo": {
                "transient": true
            }
        },
        "taskEntityUpdate": {
            "type": "Boolean",
            "value": true
        }
    }
}
2 Likes

I am calling the /task/{{taskId}}/submit-form API of Camunda. Shouldn’t it have a different Request Body?

@Mass_Shake you need to follow as per the rest api request body. From above example it’s just how to serialize the variable was shown. So refer only the “services” variable and how it’s serialized.

@Mass_Shake, They payload should be exactly like this:

{
    "variables": {
        "services": {
            "value": "[\"checkcredit\",\"validatecredit\"]",
            "valueInfo": {
                "objectTypeName": "java.util.ArrayList",
                "serializationDataFormat": "application/json"
            }
        },
        "anotherVariable": {
            "value": 42
        }
}

Thanks Aravind . I’ll try this.

Hi
I’m trying to send a list of strings to camunda process from an external task client developed in java and use that list further in the process.

I tried the following approach and it did not work

List failedaccounts;
Map<String, Object> variables = new HashMap<>();
variables.put(“flag”, false);
variables.put(“failedaccounts”, failedaccounts);
externalTaskService.complete(externalTask, variables);

Can I directly pass a java list back to camunda and how do I retrieve it back on the camunda side