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

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

chittaranjan168
Champ in-the-making
Champ in-the-making
Use ScriptTask in your process.and write

  importPackage(java.sql);
  importPackage(java.lang);
  importPackage(org.activiti.explorer.reporting);
   ReportingUtil.executeSelectSqlQuery("insert query");

agiledevpro
Champ in-the-making
Champ in-the-making
Thank you! Smiley Happy

agiledevpro
Champ in-the-making
Champ in-the-making
I've added my script to my process definition now but when I run the code I get an error saying:
javax.script.ScriptException: sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "ReportingUtil" is not defined.

This is the script:

         
               importPackage(java.sql);
               importPackage(java.lang);
               importPackage(org.activiti.explorer.reporting);
              
      ReportingUtil.executeSelectSqlQuery("insert into risk values ('123', 'someuser@gmail.com', 'Y')");
         
How can I make "ReportingUtil" defined?

Thank you!!

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

jbarrez
Star Contributor
Star Contributor
Wait - the response is not correct. Why would you want to use ReportingUtil to write data???

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

runtimeService.setVariable() is the method your looking for.

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

It works now, I used  ReportingUtil.getCurrentDatabaseConnection().prepareStatement("INSERT ..)

Regards

agiledevpro
Champ in-the-making
Champ in-the-making
The only question I now have is how to set my variables in the script?



               var p = ReportingUtil.getCurrentDatabaseConnection().prepareStatement("INSERT INTO risk VALUES (?, ?, ?)");

I know that the followning isn't possible:
               p.setString(1, ${id});
               p.setString(2, ${sender});
               p.setString(3, ${answer});

            
But I need something similar, because I want to set these ${..} in my java code.
Any suggestion on how this can be done?

Thanks

sahusunil
Champ in-the-making
Champ in-the-making
If you are using scriptTask, these variables can be accessed as process instance variable from your service task. If you are not able to access it, add activiti:autoStoreVariables="true" in your scriptTask tag and through DelegateExecution object in your java class, you should be able to access these values.

Thanks