1 Reply Latest reply on Jun 19, 2012 4:42 AM by milhaim

    Inserting new facts into a running process?

    mpgong

      Hello,

       

      I have a process that has a script task node that gets data that needs to be inserted in the knowledge session because the next task following is a business rule task.  But i don't think the rules are running because there are now facts to match against.  How are new facts inserted at runtime inside a process?

       

      I've tried this kcontext.getKnowledgeRuntime().insert(itemList) but that doesn't seem to cause the engine to fire any rules even though i know the data should.

       

      Does anyone know how to insert the facts properly?  Unfortunately i can do it ahead of time, also i insert the process into the session as well to get at process var so i hope that isn't causing any issues with things.

       

      Thanks

        • 1. Re: Inserting new facts into a running process?
          milhaim

          Hi,

           

          First you need to add a AgendaEventListener to fire all rules automatically :

           

          new AgendaEventListener() {

          .....

           

             public void afterRuleFlowGroupActivated(RuleFlowGroupActivatedEvent event,

                              WorkingMemory workingMemory) {

                            workingMemory.fireAllRules();

                      }

           

          second another listner to update the working memery after a change on the processInstane

           

          return new ProcessEventListener() {

          ....

          public void afterVariableChanged(ProcessVariableChangedEvent event) {

                org.drools.runtime.rule.FactHandle handle = event.getKnowledgeRuntime().getFactHandle( event.getProcessInstance() );

                 event.getKnowledgeRuntime().update( handle, event.getProcessInstance() );

          }

           

          more here : https://community.jboss.org/message/608017

           

          HTH