Reference to my previous topic. it is rejecting workitem but one at a time like when i run task it deletes one at a time.. can i reject in bulk so that i have to run task only one time

import sailpoint.object.*;
import org.apache.log4j.Logger;
import java.text.SimpleDateFormat;
import java.util.*;
import sailpoint.api.Workflower;
import sailpoint.object.QueryOptions;
import sailpoint.object.Filter;

Logger logger = Logger.getLogger("AIZWorkflow.CloseOpenWorkItems");
logger.debug("ENTRY : Inside CloseOpenWorkItems");

List workItemsList = new ArrayList();
List failedWorkItemsList = new ArrayList();

int workItemsCount = 0;


SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

QueryOptions qo = new QueryOptions();
qo.setCloneResults(true);
qo.addFilter(Filter.eq("type", "Approval"));		

workItemsCount = context.countObjects(WorkItem.class, qo);

Iterator workItems = context.search(WorkItem.class, qo);
logger.debug("WorkItems size::" + workItemsCount);

int i = 0;

if (workItems != null) {
  while (workItems.hasNext()) {
    i++;
    logger.debug("======================Record Number::" + i);

    WorkItem pendingWorkItem = workItems.next();
    logger.debug("WorkItem Id:::" + pendingWorkItem.getName());

    String workItemId = pendingWorkItem.getName();

    workItemsList.add("WorkItem Rejected:" + workItemId + "\r\n --------------------------------------------------------- \r\n ");

    logger.debug("pendingWorkItem match Found::" + pendingWorkItem.getName());
    try {
      logger.debug("Inside try pendingWorkItem match Found::" + pendingWorkItem.getName());
      
      Workflower workflower = new Workflower(context);
      workflower.reject(pendingWorkItem);  // Directly reject the work item
      context.decache(pendingWorkItem);    // Ensure the context is refreshed
      logger.debug("WorkItem rejected: " + workItemId);

      workItemsList.add("WorkItem Processed:" + workItemId + "\r\n --------------------------------------------------------- \r\n ");
    } catch (Exception ex) {
      logger.error("Reject WorkItem failed for: " + workItemId);
      logger.error("Reject WorkItem failed: " + ex.getMessage(), ex);
      failedWorkItemsList.add("WorkItem Failed:" + workItemId + "\r\n --------------------------------------------------------- \r\n ");
    }
  }
}

I think you’re already achieve bulk reject in your code. I can see that you’re trying to fetch all workItems and iterating. Is there anything I am missing here?

1 Like

yes but its not deleting in bulk thats my problem… i have to run task again and again because its deleting one at a time.

@autorun6464
I think on your second iteration it is going to catch block, can you please check the logged logs and see what is happening once and post the logs or error here

@autorun6464

Try this code and let me know the result, if this still doesn’t work please provide the logs


import sailpoint.object.*;
import org.apache.log4j.Logger;
import java.text.SimpleDateFormat;
import java.util.*;
import sailpoint.api.Workflower;
import sailpoint.object.QueryOptions;
import sailpoint.object.Filter;
import sailpoint.api.IncrementalObjectIterator;


Logger logger = Logger.getLogger("AIZWorkflow.CloseOpenWorkItems");
logger.debug("ENTRY : Inside CloseOpenWorkItems");

List workItemsList = new ArrayList();
List failedWorkItemsList = new ArrayList();

int workItemsCount = 0;


SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

QueryOptions qo = new QueryOptions();
qo.setCloneResults(true);
qo.addFilter(Filter.eq("type", "Approval"));		

workItemsCount = context.countObjects(WorkItem.class, qo);

IncrementalObjectIterator workItems = new IncrementalObjectIterator(context, WorkItem.class, qo);
logger.debug("WorkItems size::" + workItemsCount);

int i = 0;

if (workItems != null) {
  while (workItems.hasNext()) {
    i++;
    logger.debug("======================Record Number::" + i);

    WorkItem pendingWorkItem = workItems.next();
    logger.debug("WorkItem Id:::" + pendingWorkItem.getName());

    String workItemId = pendingWorkItem.getName();

    workItemsList.add("WorkItem Rejected:" + workItemId + "\r\n --------------------------------------------------------- \r\n ");

    logger.debug("pendingWorkItem match Found::" + pendingWorkItem.getName());
    try {
      logger.debug("Inside try pendingWorkItem match Found::" + pendingWorkItem.getName());
      
      Workflower workflower = new Workflower(context);
      workflower.reject(pendingWorkItem);  // Directly reject the work item
      context.decache(pendingWorkItem);    // Ensure the context is refreshed
      logger.debug("WorkItem rejected: " + workItemId);

      workItemsList.add("WorkItem Processed:" + workItemId + "\r\n --------------------------------------------------------- \r\n ");
    } catch (Exception ex) {
      logger.error("Reject WorkItem failed for: " + workItemId);
      logger.error("Reject WorkItem failed: " + ex.getMessage(), ex);
      failedWorkItemsList.add("WorkItem Failed:" + workItemId + "\r\n --------------------------------------------------------- \r\n ");
    }
  }
}

2 Likes

Yup it works… Thank you so much

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.