Adding multiple Documents programmatically



for a university project I'm currently writing a receiver in Java which reads incoming mails and puts their attachments to a bonita process. We are currently only using the 6.X UI for simplicity.

At the begin I started with one PDF attachment and a single document in my process.
My Java code is as follows:
public void createCaseWithDocument(String processDefinitionName, String processVersion,
Map<String, Object> variables, List<Attachment> documents)
throws ProcessDefinitionNotFoundException, InvalidExpressionException, ProcessActivationException,
ProcessExecutionException, BonitaHomeNotSetException, ServerAPIException, UnknownAPITypeException {
ProcessAPI processAPI = TenantAPIAccessor.getProcessAPI(apiSession);
long processDefinitionId = processAPI.getProcessDefinitionId(processDefinitionName, processVersion);
// ----- create list of operations -----
List<Operation> listOperations = new ArrayList<Operation>();
// variables
Map<String, Serializable> ListExpressionsContext = new HashMap<String, Serializable>();
for (String variableName : variables.keySet()) {
if (variables.get(variableName) == null || (!(variables.get(variableName) instanceof Serializable)))
Object value = variables.get(variableName);
Serializable valueSerializable = (Serializable) value;
variableName = variableName.toLowerCase();
Expression expr = new ExpressionBuilder().createExpression(variableName, variableName,
value.getClass().getName(), ExpressionType.TYPE_INPUT);
Operation op = new OperationBuilder().createSetDataOperation(variableName, expr);
ListExpressionsContext.put(variableName, valueSerializable);
// update document
for (Attachment document : documents) {
String documentName = document.fileName();
DocumentValue documentValue = null;
documentValue = new DocumentValue(document.fileData(), document.mimeType(), documentName);
Operation docRefOperation = new OperationBuilder().createSetDocument("bewerbung", new ExpressionBuilder()
.createInputExpression(documentName + "Reference", DocumentValue.class.getName()));
ListExpressionsContext.put(documentName + "Reference", documentValue);
// ----- start process instance -----
processAPI.startProcess(processDefinitionId, listOperations, ListExpressionsContext);

Mostly taken from the documentation. The Attachment-type contains a byte-Array (fileData), the filename and the mime-type (application/pdf only at the moment).

When just attaching one file it works like a charm. At the moment I add a second file, the first file is overwritten. Sure, it's a "single" document so I put it to "multiple". Now I get errors that the Widget for Files (6.X) does not work with multiple documents. Is there any workaround without going over to UI Designer forms which apparently start to be an even bigger mess. Because after creating a contract and letting the UI Designer automatically do a UI, apparently documents that I add programmatically aren't even shown anymore in the process overview.

Probably my java code is wrong and not suitable for documents with "multiple option", but I didn't find a documentation for adding multiple documents to a single process document with "multiple option".

Thanks in advance,

No answers yet.