cancel
Showing results for 
Search instead for 
Did you mean: 

Java Activiti Inputs

chunnu
Champ in-the-making
Champ in-the-making
I am learning Java Activiti in order to connect a process through Java Spring MVC.

I have used the Java Service Task and my code executes. What I want to do is when the process starts I want the client to send inputs. For example send a name. How is this possible through Java Activiti? I have tried all things but can't find what I need.

Also, I would like the process to output something.
16 REPLIES 16

jbarrez
Star Contributor
Star Contributor
What you need is a form that is displayed to the user. All the input of the user is then sent to the engine as process variables.
Check the startProcessInstance method that accepts a map of variables. Same for completing user tasks.

chunnu
Champ in-the-making
Champ in-the-making
Hi

Actually there is no user interface. The data input will be coming through JSON.

Data wil come through JSON into Spring MVC. Then the Activiti engine will start. So in this case how should I do it for input and output?

chunnu
Champ in-the-making
Champ in-the-making
Hi

When replying could you please give an example of how it is done.

jbarrez
Star Contributor
Star Contributor
Just convert the json to whatever object you want, and call the runtimeService.startProcessInstance method and pass your variables there. It would be an example of two lines 😉

chunnu
Champ in-the-making
Champ in-the-making
Hi

Ok, I got the input process variable to work.

The code will exeucte like a Service without any user involment. Basically there is a user interface. User interface adds information to JSON. The Java code which is the JavaDelegate  will execute to do something that doesn't involve a user. When the code has finished it will give a success back to JSON which in turn will tell client.

The sucess is the output variable. How can this be created? I can create it in the JavaDelegate but when the code has completed how can it be accessed through the process instance?

From the output variable I would like to print the result.

jbarrez
Star Contributor
Star Contributor
So if I understand you correctly, when the user fills in a form, a fully automated process is started and finished. And you need the outcome of that process.

First of all: do you really need a workflow/process for this? Feels like mis-using a bpm engine.

But to answer your question: the easiest is probably storing the outcome as a process variable, and fetching the last value of that variable from the process history.

chunnu
Champ in-the-making
Champ in-the-making
Hi

Yes that's right and for now I do need it.

I am unable to locate the method in the HistoryService. Can you tell me which method should be called to get the output variable?

jbarrez
Star Contributor
Star Contributor
Check

/** Creates a new programmatic query to search for {@link HistoricDetail}s. */
  HistoricDetailQuery createHistoricDetailQuery();

if you're on 5.10.

If you're adventurous and want to have an easier way, check trunk:
 
  /** Creates a new programmatic query to search for {@link HistoricProcessVariable}s. */
  HistoricProcessVariableQuery createHistoricProcessVariableQuery();

chunnu
Champ in-the-making
Champ in-the-making
Hi

I am on version 5.10. I am not sure which method to call on the 1st 1 you are saying and for the other 1 HistoricProcessVariableQuery I cannot see this on the API. Is this version 5.10?