0 Replies Latest reply on Oct 11, 2017 4:53 AM by Grzegorz Sz

    How to compensate workItem which throw exception (workItem is in state PENDING)

    Grzegorz Sz Newbie

      It's possible to send signal "compensation" for workItem in PENDING state ? I see it's possible to send signal for workItem in state COMPLETE or ABORTET but there process is go further.

      My workItem is in state pending because throws exception and I want to handle error of workItem and reverse done jobs in compensation


      I don't want to abort workItem, because it skip execution of error handling subprocess and process goes further like in success path.


      I try some code:


      public ManualCompensationWorkItemHandler(KieSession ksession) {
          this.kieSession = ksession;

      public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) {
          Map<String, Object> parameters = workItem.getParameters();

          Object obj = parameters.get("workItemWithErrorAsParam");
          if (!Objects.isNull(obj)) {
              WorkItem workItemWithError = (WorkItem) obj;
              ProcessInstance processInstance = kieSession.getProcessInstance(workItemWithError.getProcessInstanceId());

              Node[] processNodes = ((WorkflowProcessInstanceImpl) processInstance).getNodeContainer().getNodes();
              for (int i = 0; i < processNodes.length; i++) {
                  Node node = processNodes[i];
                  if ("WorkItem name which throw exception".equals(node.getName())) {
                      ((org.drools.core.process.instance.WorkItemManager) workItemManager).signalEvent(COMPENSATION_EVENT_TYPE, node.getMetaData().get("UniqueId"));
              invokeProcessCompensation((org.drools.core.process.instance.WorkItemManager) workItemManager, processInstance);
              abortProcessInstance(workItem, processInstance);

          HashMap<String, Object> results = Maps.newHashMap();
          workItemManager.completeWorkItem(workItem.getId(), results);