1 Reply Latest reply on Dec 12, 2013 3:22 AM by Maciej Swiderski

    Error in Custom workitem Handler

    PANKAJ M Newbie

      I am trying to get process variables in a custom work item handler. My process has a human task immediately after it starts. That triggers execution of the custom work item handler. I try to retrieve process variables in the handler but the getProcessInstance() throws error because jBPM has not written byteArray yet into the processInstanceInfo table.


      Can any one help me with writing this correctly. I am using jBPM 6. Is there a better way?






      Here is the code



      public class TaskWorkItemHandler implements WorkItemHandler {

         public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {

        KieSession ksession = ProcessRun.getSession();

        long procId = workItem.getProcessInstanceId();

        ProcessInstance p = ksession.getProcessInstance(procId);  // return exception

         WorkflowProcessInstance w = (WorkflowProcessInstance)p;






      public class ProcessRun


        public void run()




         KieSession ksession = getSession();

        JPAWorkingMemoryDbLogger logger = new JPAWorkingMemoryDbLogger(ksession);

        HashMap<String,Object> h = new HashMap<String,Object>();


        ProcessInstance pi = ksession.startProcess( "com.sample.evaluation",h );


        catch (Exception e)







        public static KieSession getSession()


        KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

        kbuilder.add(ResourceFactory.newFileResource("c:\\temp\\HR.bpmn"), ResourceType.BPMN2);

         KnowledgeBase kbase = kbuilder.newKnowledgeBase();

        EntityManagerFactory emf =   Persistence.createEntityManagerFactory( "org.jbpm.persistence.jpa" );

         Environment env = KnowledgeBaseFactory.newEnvironment();

        env.set( EnvironmentName.ENTITY_MANAGER_FACTORY, emf );

        env.set( EnvironmentName.TRANSACTION_MANAGER,TransactionManagerServices.getTransactionManager() );

         KieSession ksession =

           JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env );

        ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new TaskWorkItemHandler());

        return ksession;