cancel
Showing results for 
Search instead for 
Did you mean: 

Start process synchronously and return results Back

smirzai
Champ on-the-rise
Champ on-the-rise
Actually this is a continuation of this topic:
   http://forums.activiti.org/content/starting-process-instance-synchronously


Especially in OLTP or embeded use cases, one wants to run the workflow and get the results synchronously. In some cases there is no real database behind or the performance requirements are too strict to enable historization.

What I would like to suggest, is something like this:

First the output variables should be introduced exactly like subprocess, only for the main process. Here is an example:


<process id="vacationRequest" name="Vacation request">
     <extensionElements>
          <activiti:out source="someVariableInSubProcss" target="nameOfVariableInMainProcess" />
  </extensionElements>

    <startEvent id="request" activiti:initiator="employeeName">  …


then it could be something like :
    Map<String,Object> outcome = myRuntimeService.startInstance("myProcess", vars);

will start the process, wait until it ends, then preserves and returns the result from context and not history tables.
I can try to see how I can implement it. 
17 REPLIES 17

fnoorie
Champ in-the-making
Champ in-the-making
@Joram

Referring to your answer above:

"If your process is 100% synchronous, simply pass an object in the variables map, and populate the object values during process execution.
When your process finished, the object will now have all the values set. This already works now and doesn't need any new implementation work."

My process is as follows:

<code>
Map<String, Object> variables = new HashMap<String, Object>();
        variables.put("accountNumber", accountNumber);
        variables.put("errorFlow", false);
        variables.put("respObject", null);
        variables.put("respStatus", null);
        RuntimeService runtimeService = processEngine.getRuntimeService();
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("GetAccountPriceCategory", variables);
</code>

In one of the tasks I set the following:
<code>
execution.setVariable("respObject", accountPriceCategory);
execution.setVariable("respStatus", Status.OK);
</code>

But when the process finishes respObject and respStatus are null.

jbarrez
Star Contributor
Star Contributor
No, the respObject would need to be a real object, with a member field for the stuff you want to store.

jubedus
Champ in-the-making
Champ in-the-making
Hi Joram,

  Could you please post an example of using a real object for returning values from a workflow? I haven't been able to implement it with Activiti 5.19.0. Thanks a lot in advance!

jbarrez
Star Contributor
Star Contributor
You simply create a Pojo, with some member fields. You pass it when doing startProcessInstanceByKey(key, variables) in the variables map. When the process is straight through, all the changes that have been done in the process to the pojo will be in the actual pojo (as no copy has been made … this only works for a straight through process!)

gourahari_activ
Champ in-the-making
Champ in-the-making
Hi jbarrez,
I am new to Acititvi BPM. I read lots of post ,books,forums.
Could you please explain with simple example , How an html form will call "start Event" . I mean to say how external third party UI will call BPM and controll the all activiti.

Actitviti User guide doed not help me . I am using ACTVITI-5x

If you will explain me ,it will great help.

Thanks in advance.

gourahari_activ
Champ in-the-making
Champ in-the-making
Hi jbarrez,
I am new to Acititvi BPM. I read lots of post ,books,forums.
Could you please explain with simple example , How an html form will call "start Event" . I mean to say how external third party UI will call BPM and controll the all activiti.

Actitviti User guide doed not help me . I am using ACTVITI-5x

If you will explain me ,it will great help.

Thanks in advance.

jbarrez
Star Contributor
Star Contributor
I responded to your duplicate of this post somewhere else.

chary
Champ in-the-making
Champ in-the-making
Below is the sample code:
***********

Map<String, Object> map = new HashMap<String, Object>();
map.put("appId", appId);
map.put("appName", appName);

/* to catch workflow execution result */
map.put("regResult", new AppRegistrationResult());

ProcessInstance process = this.processEngine.getRuntimeService()
     .startProcessInstanceByKey("AppRegistrationProcess", map);

/* extract the result */
AppRegistrationResult registrationResult = map.get("regResult");