4 Replies Latest reply on Oct 20, 2011 10:57 AM by Ryan Peterson

    How to get active processes via ksession.getProcessInstances()  (Jbpm 5.1.1)

    Ryan Peterson Newbie

      Hey guys,


      I'm using a single StatefulKnowledgeSession to manage my processes.  Each processInstance is mapped to a userId, which is stored in the params map as a process variable upon the start of the process: 


      ksession.startProcess(processId, params)


      Later I'd like to check if a specific userId exists in the workflow engine, which I was hoping to check all the active processInstances and search for the userId within their processVariables.


      Unfortunately when I use ksession.getProcessInstances() I get 0 results.  If I "cheat" and use ksession.getProcessInstance(procInstId) it returns with a status of Active, so it's definitely there & active.


      Is there a way to do a "deep" search to find the active processes?  Is it necessary to store a list of every instantiated process ID to query the ksession individually? 

      I am persisting the processes and StatefulKnowledgeSession, but I have not called .dispose() and am still in the same jvm instance (haven't restored the ksession from the database).


      Is there a better way to find if a user is already in a workflow based on process variables?


      Thanks for any help!