cancel
Showing results for 
Search instead for 
Did you mean: 

record of database as input for workflow

striker_sfc1
Champ in-the-making
Champ in-the-making
Hi people.

I have a table in my postgresql DB. I need of read records from the database and use some fields as input to start a workflow.
At the moment I can read the input parameters from a form (for testing the workflow), but i need of automate the process reading those parameters from a DB.

thanks
Alex
15 REPLIES 15

meyerd
Champ on-the-rise
Champ on-the-rise
Hi striker_sfc,

Just write some Java Classes that read these items of Data from the Database and pass them to the process instance when stating the process.

striker_sfc1
Champ in-the-making
Champ in-the-making
We suppose that i have a dbconnection in a java class and I had read the fields that I need and I store it in the following variables:

String name = resultSet.getString("DB_name");
String surname = resultSet.getString("DB_surname");
String role = resultSet.getString("DB_role");

and now i need of start a instance of my workflow called "myWorkflow" with those parameters as input.

Can you write for me the sting that pass the variables to my workflow instance and launch it?

thanks for the quickly reply. Smiley Tongue
Alex

meyerd
Champ on-the-rise
Champ on-the-rise
Hi striker_sfc,

Just put you data in a java.util.Map:

Map<String, Object> processVariables = new HashMap<String, Object>();
processVariables.put("name", name);
processVariables.put("surname", surname);


runtimeService.startProcessInstanceByKey("myWorkflow", processVariables);

In the bpmn20.xml you can then reference the vaiables using ${name}, ${surname} and so forth

meyerd
Champ on-the-rise
Champ on-the-rise

striker_sfc1
Champ in-the-making
Champ in-the-making
Perfect! I will test it soon…
Thanks a lot for your help!

Alex

striker_sfc1
Champ in-the-making
Champ in-the-making
I test your solution and…

1) I must use HashMap<String, Object> processVariables = new HashMap<String,Object>();

because if i use Map<String, Object> processVariables = new HashMap<String,Object>() i have this error:

" Type mismatch: cannot convert from HashMap<String,Object> to Iterators.Map<String,Object> "

2) I have a problem on ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("wf1", processVariables) :
" runtimeService cannot be resolved "

infact eclipse with ctrl+space give me RuntimeService (interface of org.activi.engine)
but if I use
ProcessInstance processInstance = RuntimeService.startProcessInstanceByKey("wf1", processVariables)

eclipse said

The method startProcessInstanceByKey(String, String) in the type RuntimeService is not applicable for the arguments (String, Iterators.Map<String,Object>)

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
1: learn java
2a: see 1
2b: read the manual, look at examples,

striker_sfc1
Champ in-the-making
Champ in-the-making
I resolve the first problem… but not the second.

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
Look at the CDI chapter…