cancel
Showing results for 
Search instead for 
Did you mean: 

Possible to store data in a step?

agiledevpro
Champ in-the-making
Champ in-the-making
Hi,

I'm using an external database (mysql) instead of the default database. And I wonder if it is possible to insert data into my database in a step of a process?

The data is received from a java class and I want this data to be inserted through a step in my bpmn20.xml file.

If this is possible, could I be given some example code of how this can be done?


Thanks in advance!
12 REPLIES 12

Hi, thank you for your answer.

You said that "…as process instance variable from your service task", did you mean script task?
Maybe I was unclear in my question.

What I want to do is when I reach the scriptTask in my process I want to insert values into the database. The values to be inserted is received from an email which I've read  in a Java class and it is these values that I want to insert as soon as the execution is at my scriptTask.

From my java class I want to do something like:
Execution execution = runtimeService.createExecutionQuery()
.processInstanceId(pi.getId())
.activityId("ScriptState")
.singleResult();
runtimeService.signal(execution.getId(), varToInsert);

And in my scriptTask i need something like:
importPackage(java.sql);
importPackage(java.lang);
importPackage(org.activiti.explorer.reporting);
              
var p = ReportingUtil.getCurrentDatabaseConnection().prepareStatement("INSERT INTO risk VALUES (?, ?, ?)");
              
p.setString(1, ${id});
p.setString(2, ${name});
p.setString(3, ${answer]);
p.executeUpdate();


Anyone?

Regards,

agiledevpro
Champ in-the-making
Champ in-the-making
?

agiledevpro
Champ in-the-making
Champ in-the-making
Problem is now solved.

The problem was solved by setting the variables in the step above my scipttask and then I could use these variables in my scripttask.


activiti:in source="uuid" target="${uuid}"


extensionElements
receiveTask

<scriptTask id="storeValues" name="Execute script" scriptFormat="JavaScript" activiti:autoStoreVariables="false">

          <script><![CDATA[
         
               importPackage(java.sql);
               importPackage(java.lang);
               importPackage(org.activiti.explorer.reporting);
              
               var p = ReportingUtil.getCurrentDatabaseConnection().prepareStatement("INSERT INTO risk VALUES (?, ?, ?)");
               var id = uuid;
               var sender = user;
               var answer = ans;

Regards,
Alexandra