How to read external configuration file in service task?

How can we read external configuration file in a service task which has inline script written in Java Script ?


I have requirement in which I have to read some properties from a external file and use it in my script file to assign them to a variable.

How do camunda keep and read external caongiguration files ?

take a look at this specific post:

Hi @StephenOTT

Thanks for the reply !!!

So I dont want to write a script at start event instead i want to read a file placea at some external location in my script task. Script Type is Javascript.

Is there any way in which we can read external files ?

My use case is I want to assign some value to variable which is not workflow dependent and which a user can change at any point of time without changing the bpmn file.

@paritosh took at the specific post that i linked to. The specific post has a code sample that is for “loading a config file”, but you can modify that script to load any file you wish, and instead of loading that file from the process deployment resources, you can point your script to a network volume where you are storing your config file.

something like

var classloader = java.lang.Thread.currentThread().getContextClassLoader()
var myConfigFile = classloader.getResourceAsStream('configs/myConfigFile')

So you are using the script in the link as a base: all of the parts you need / logic are in that code snippet example. Just modify it for your purpose of loading from a external file (like in the two lines above), and then set your process variable based on the config file data.

Hi @StephenOTT Thanks for the solution. One thing i want to know here, i was getting the file as bytearray inputstream and i tried to convert the inputstream to string using the link you have provided but i am getting the following error -
Unable to evaluate script: ReferenceError: “Java” is not defined.

please let me know what should be the correct way to convert the bytearrayinputstream to String in the script task

Can you share your snippet of code/script?

Hi @StephenOTT Here is the code snippet

var classloader = java.lang.Thread.currentThread().getContextClassLoader()
var resource = classloader.getResourceAsStream(‘workflow/’)
var IOUtils = Java.type(‘’);
var String = Java.type(‘java.lang.String’);
var myConfigFile = S(new String(IOUtils.toByteArray(resource), ‘UTF-8’));

What line is throwing the error?

var IOUtils = Java.type(‘’);

Here Java is not understandable in inline script

You are running your script as a async job? likely running into this issue: cannot be found when task runs as Job

My original code snippet has the proper usage without needing the IOUtils. Reasons for the usage can be found in the link above.