How to load a file in an automatic or service task ?



I am using the 7.11.4 community version.

A task of my process launches an external script that generates a result file in a specific directory.

I would like to build a task that :

- checks if the file exists

- if yes, automatically loads it in a document.

So far, the only ways to upload a document that I have found, are either to use the UI Designer upload widget, or to create the document from an external file, at the start of the process.

Can Someone help me ?

Thank you in advance,


1 answer

This one is the BEST answer!

Hi Thierry,

How do you know the path of the generated file ? Is it a process parameter or variable ? If you know the path you can create an operation on task that assign the content of the file to a Document like this:

Left operand: yourDocumentVariable
Operator: **Set Document ** Right Operand: a script returning a org.bonitasoft.engine.bpm.document.DocumentValue with the following content:

import java.nio.file.Files

def file = new File('your/file/path/on/server')
def mimeType = Files.probeContentType(file.toPath())
new DocumentValue(file.bytes, mimeType,

There is a reference article in the documentation about documents.



Submitted by brt6178_1422639 on Wed, 01/27/2021 - 10:55

Hello Romain,

thank you for your answer. It works perfectly well !!

I know the path of the file, because for the moment, it is hardcoded in a process parameter.

I haven't heard about the java.nio.file.Files class before (I'm not comfortable with java), and I think it will help me a lot.