0
votes

Is there a way by which we can modify the data of a process instance in jBPM which is already started (after starting the instance).

I have started a process using

ProcessInstance processInstance = ksession.startProcess(procId,params);

and now after some event I need to modify the process instance data :

((WorkflowProcessInstance) processInstance).setVariable("transit_To", "DONE");

This gives me error: Process instance 875[or.example.proc] is disconnected.

Any sort of information would be really helpful.

Thanks.

1

1 Answers

0
votes

I has created a class UpdateVariableCommand witch implements GenericCommand.

@Override
public Object execute(Context context) {
    KieSession ksession = ((KnowledgeCommandContext) context).getKieSession();
    WorkflowProcessInstance processInstance = (WorkflowProcessInstance) ksession.getProcessInstance(instanceId);
    VariableScopeInstance variableScope = (VariableScopeInstance) processInstance
            .getContextInstance(VariableScope.VARIABLE_SCOPE);
    variableScope.setVariable(name, value);
    return true;
}

I updating the variable like this:

/**
 * @param processInstanceId 
 * @param name of variable
 * @param value of variable
 */
public void setVariable(Long processInstanceId, String name, Object value) {
    UpdateVariableCommand command = new UpdateVariableCommand(processInstanceId, name, value);
    ksession.execute(command);
}