Data Persistence

Hi,

Iam newbiee to camunda , I haven’t done much analysis but feel to ask some questions regarding data persistence. I have used JBPM for a while , it has a data modeller in which user can create objects of our own type and facility to persist in database . Say i have an object person having name, age , addresses attributes. which is binded to task forms. Once the process starts the user provided data will be persisted in person table.

Does camunda supports any thing like this. ?

Hi @Ajr
No equivalent data modeler in camunda.
You could handle it in many ways
In case you are using embedded forms then one easy way is to use Json Variables as in below links

https://blog.camunda.org/post/2015/02/json-everywhere-how-to-use-json-in/

Hi @hassang

Thanks for your suggestion,will look at it.

Thanks
Ajr

Have you considered using DMN tables for persistence? That may be a very ignorant question, but I know you can store information in them that can be extracted based upon certain criteria. This is a very simple form of what JBPM decision support provides, but might help.

Michael

Hi @mppfor_manu,

From my understanding DMN tables are kind of rules table which are used as a decision point in workflow. My requirement is some what different from that . I want data given in the form to be persisted in my own tables.

Thanks
Ajr

You are correct about the DMN tables. Perhaps I’m oversimplifying your requirements, but it sounds like you want to take data from a form and store it in a database. To do that, you would need use a script (JavaScript or Groovy) or write some Java code that would take these variables and store them in a database.

Conceptually, you would put the form input into process variables. For example, if your form had an account number field, you would use something like this in JavaScript:

execution.setVariable(“accountNumber”, currentAccountNumber);

Then, you would execute code to put that data into the database. I’m sorry, but I haven’t actually done this. However, I would use a Java class. It would need to contain something like this:

import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;

public class StoreFormData implements JavaDelegate {

String accountNumber = (String) execution.getVariable("currentAccountNumber") ;


}

The URL below has a simple example of how to perform the insert into MySQL. The key here is understanding how you can set the process variable with form data and then retrieve that data so that you can insert it into a database.

http://alvinalexander.com/java/edu/pj/jdbc/jdbc0002

I hope this helps.

Michael

1 Like

Hi @mppfor_manu ,

Thanks for your reply. My requirement is little bit complex. I have a request form for getting approval for purchasing some items. In the user task form , user provide a list of items they want to purchase . So i need to hold all these element as a list. How can i persist these to a database with help of camunda.

Again appreciating your response.

Thanks
Ajr

Within Camunda, you could use a Listener to execute the database inserts. In the workflow you can use a Listener to execute code before or after a task. In the case of the example I provided, you might be use an “Event end” Listener. When defining the Listener, you would set the “Listener Type” to “Java Class”. In the “Java Class” box, you would put the name of the Java class you created to perform the insert (example: com.ajr.StoreOrderForm). This class would need to made available within whatever Java container you are running Camunda.

You would create a table in the database that contains a column with a unique ID (example: the session ID) and columns for each line item of the order form (example: part number, quantity, cost, etc.). Once you retrieve the data from the list, you would insert records into the database using the unique ID column as the key. When you want to retrieve that particular order, you would select rows from the table that matched the unique ID.

This is an over simplification of what you would need to in the database itself. You would need a table for the customer information, a table for inventory, etc. But this is the basic idea of how you might store form data.

I am not an experienced Java or JavaScript programmer, so there are limits to what I can help you with here.

Michael

Hi @Ajr

Please see below post