Question

How to set/modify the process instance variables of a running process-instance in JBPM ? Is there any pre-defined command class to set the process-instance-variables ?

I can see some commands like org.drools.command.SetVariableCommandFromLastReturn && org.drools.command.SetVariableCommandFromCommand

Can I use these commands ? How to use this command ?

Was it helpful?

Solution

As of now I am updating the variables like this with GenericCommand.

kSession.execute(new GenericCommand<Boolean>() {
            public Boolean execute(Context context) {
                //Get session in the command context
                StatefulKnowledgeSession ksession = ((KnowledgeCommandContext) context).getStatefulKnowledgesession();
                //Get the process instance
                ProcessInstance processInstance = (ProcessInstance) ksession.getProcessInstance(processInstanceId);
                //Get variable scoprts
                VariableScopeInstance variableScope = (VariableScopeInstance) processInstance.getContextInstance(VariableScope.VARIABLE_SCOPE);
                Iterator<String> piStateItr=piStateVariables.keySet().iterator();
                //Modify required variables
                while(piStateItr.hasNext()){
                    String variableName=piStateItr.next();
                    String variableValue=piStateVariables.get(variableName);
                    logger.debug(">>> Setting State - key "+variableName +" , to "+variableValue );
                    variableScope.setVariable(variableName, variableValue);
                }
                return true;
            }
        });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top