AnsweredAssumed Answered

Out Variables from a Primary Process - A Proposal

Question asked by tidetom on May 24, 2011
Latest reply on May 25, 2011 by ronald.van.kuijk
One of the primary areas that has been a source of difficulty for my group in working with Activiti is the inability to specify "out" variables from a primary process.  Mainly, we're working with Activiti using Spring integration, and we typically have a Spring Bean that kicks off a new Activiti process, using something like this:

       Map<String,Object> variableMap = new HashMap<String,Object>();
        … populate variableMap with inputs from the client-tier …

        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myprocess",variableMap);

        // Check the after variables to see if any errors occurred, etc.
        Map<String, Object> afterVariables = runtimeService.getVariables(pi.getId());
        … check the after variables for error messages that have stacked up, send the error messages back to the user …

However, in order to invoke runtimeService.getVariables(pi.getId()) to get the variables out of the process, the process itself needs to be unfinished.  This means that prior to the end of our process, we need to stick a Java Receive Task on there to stop the process from finishing in order for the above code to work.  Then, after we grab the afterVariables and check them in the segment above, we signal the process itself to complete:

        // Finish the process by triggering the "finishProcessReceiveTask"
        Execution finishProcessTaskExecution = runtimeService.createExecutionQuery().processInstanceId(
                processInstance.getId()).activityId("finishProcessReceiveTask").singleResult();
        runtimeService.signal(finishProcessTaskExecution.getId());

While it works, it seems a little bit like a hack having to put a Java Receive Task before the end of every primary process just to check variables that were set in the process execution flow.

I know that one of the responses to this is that you can simply set the history value to full in the process engine configuration, however this means (in our scenario at least) that megabytes of data would get saved in the database for every process, when all we care about is a few kilobytes of "out" data.

    <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
        …
        <property name="history" value="audit" />
        …
    </bean>

My question is:  How are other people handling "out" variables like these? Am I missing something critical that I'm not thinking about?

Lastly (assuming I'm handling things properly given my use case), I'm wondering if the Activiti developers out there might consider this proposal:

Activiti already allows you to specify "in" and "out" variables when invoking a sub-process via the CallActivity task.  Yet, when invoking a primary process, we currently only get the capability of specifying "in" variables (via the variableMap specified in the runtimeService.startProcessInstanceByKey(processKey,variableMap) method defined above).  Would there be a way that you could add the ability to register for out variables, or pass in a simple map that will contain all of the out variables in a process, without being dependent on a currently executing process?

Thanks in advance for your time.
Tom

Outcomes