-
1. Re: Access variables bound to process instance during its lifecyle
roxy1987 May 23, 2013 3:11 PM (in response to hoang_to)1 of 1 people found this helpfulTo read a process variable you could use the following code :
public Map<String, Object> getProcessVariables(final long intProcessInstId ) { StatefulKnowledgeSession objKSession = getSession(); //Get the session Map<String, Object> hshVariables = null; try { hshVariables = objKSession.execute(new GenericCommand<Map<String, Object>>() { private static final long serialVersionUID = 1L; public Map<String, Object> execute(Context objContext) { StatefulKnowledgeSession objKSession = ((KnowledgeCommandContext) objContext) .getStatefulKnowledgesession(); org.jbpm.process.instance.ProcessInstance objProcessInstance = (org.jbpm.process.instance. ProcessInstance) objKSession. getProcessInstance(intProcessInstId); VariableScopeInstance objVariableScope = (VariableScopeInstance) objProcessInstance. getContextInstance(VariableScope.VARIABLE_SCOPE); /*Obtiene las variables del Proceso*/ Map<String, Object> hshVariables = objVariableScope.getVariables(); return hshVariables; } }); } catch(Exception objException) { objLogger.loggerError(objException); } return hshVariables; }
And to put a variable in the process
public void setProcessVariables(final long intProcessInstId, final Map<String, Object> hshVariableMap)
{
StatefulKnowledgeSession objKSession = getSession(); //Get the session
try {
objKSession.execute(new GenericCommand<Map<String, Object>>() {
private static final long serialVersionUID = 1L;
public Map<String, Object> execute(Context objContext) {
StatefulKnowledgeSession objKSession = ((KnowledgeCommandContext) objContext).
getStatefulKnowledgesession();
org.jbpm.process.instance.ProcessInstance objProcessInstance = (org.jbpm.process.instance.
ProcessInstance) objKSession.
getProcessInstance(intProcessInstId);
VariableScopeInstance objVariableScope = (VariableScopeInstance) objProcessInstance.
getContextInstance(VariableScope.VARIABLE_SCOPE);
Iterator<Map.Entry<String, Object>> objIterator = hshVariableMap.entrySet().iterator();
Map.Entry<String, Object> objPairs;
while(objIterator.hasNext()) {
objPairs = (Map.Entry<String, Object>)objIterator.next();
objVariableScope.setVariable(objPairs.getKey(), objPairs.getValue());
}
return null;
}
});
} catch(Exception objException) {
objLogger.loggerError(objException);
}
}
-
2. Re: Access variables bound to process instance during its lifecyle
hoang_to May 27, 2013 11:42 PM (in response to roxy1987)Ok, so the gist is to wrapp business code requiring contextual variables in callback (to have access to Context object). Thanks Shobhit
-
3. Re: Access variables bound to process instance during its lifecyle
prathap.vs Jun 17, 2013 5:38 AM (in response to hoang_to)Hi,
We are trying to find process variables by the method mentioned above. But we are unable to find process variables. The list is coming as empty. We have defined two process variables in vardefs section while creating a workflow process in designer. Let me know if you have got through this approach and got process variables.
Thanks,
Prathap
-
4. Re: Access variables bound to process instance during its lifecyle
hoang_to Jun 17, 2013 6:03 AM (in response to prathap.vs)@Prathap: Make sure that while you created your process definition via web-based editor, you have defined a list of variables. Just open the process definition editor, then click the arrow button on right side of editor to show the popup allowing to edit metadata (including list of variables) of your process
Having played with JBPM for a while, i figured out that fetching variables in this way is not a good manner. We had better configure the process variable <--> task params bindings in process designer tool
-
5. Re: Access variables bound to process instance during its lifecyle
ashpcs Jun 21, 2013 9:34 AM (in response to hoang_to)Hi Minh,
can you let me know why--> n click the arrow button on right side of editor to show the popup allowing to edit metadata (including list of variables) of your process.
Is not a good idea? Is it because of designer limitation?