2 Replies Latest reply on Jun 19, 2012 6:41 AM by Pedro Gonçalves

    Link the business object to the process instance

    Pedro Gonçalves Newbie

      I want to link my business objects to the process instances in jbpm5.3. What is the best way to do it? Using variables?

       

      I will need to have it linked in a way that I can easily query and get the history of some business object.

       

      In jbpm4 and in activiti there where some pretty easy way to do it, with a so called Business Key. I've played with it a bit, and find very easy to create a history of ongoing and completed workflows, but I'm struggling to find what is the best way to do it with jbpm5.

       

      Thanks in advance.

        • 1. Re: Link the business object to the process instance
          Mauricio Salatino Master

          Using variables and persisters you can achieve that.. The history will be keep by the history loggers.

          Variables and Persisters do the Business keys for you.

          • 2. Re: Link the business object to the process instance
            Pedro Gonçalves Newbie

            Thanks Mauricio.

            I've used the Variables to build Business Keys.

             

            This is how I've managed to solve the problem:

             

             

            
            //......Start process......
            Map<String, Object> variables = new HashMap<String, Object>();
            
            variables.put("business_key", buildBusinessKeyForMyObject(myObject));
            
            kSession.startProcess("my_workflow_id",variables);
            //......................................
            
            
            
            //.........Get Process Instances Id of My Object.......
            Query query = entityManager.createQuery("FROM " + VariableInstanceLog.class.getName() + " variable " +
                  " WHERE variable.variableId = :business_key_id
                     AND variable.value = :business_key_value);
            
                 query.setParameter("business_key_id", "business_key");
                 query.setParameter("business_key_value", buildCoreDataBusinessKey(coreData));
            
                 List<VariableInstanceLog> resultList = query.getResultList();
            
            for (VariableInstanceLog variableInstanceLog : resultList) {
                 logger.info("******* " + variableInstanceLog.getProcessInstanceId());
            }
            //...............................................................