Wanted to run rule to execute workflow multiple times with different values

Dear Everyone,

I am trying to execute one rule, rule will iterate the custom object and loop the object in custom object and execute the Workflow with their associated values in each loop.

code is working fine in first loop but giving error in following loops.

error looks very basic, but I didn’t understand what the issue here.

Attaching the Rule and custom object and error message:

Error Massage:

LunchWorkflowRule.java (2.8 KB)

CustomObject.xml (1.5 KB)

Exception running rule: BeanShell script error: bsh.EvalError: Sourced file: inline evaluation of: import java.text.SimpleDateFormat; import java.util.Calendar; import java.ut . . . '' unknown error: null : at Line: 50 : in file: inline evaluation of: import java.text.SimpleDateFormat; import java.util.Calendar; import java.ut . . . ‘’ : if ( requestList != null && ! requestList .isEmpty ( ) ) {
BSF info: CBQ Lunch workflows Branch Change at line: 0 column: columnNo

thanks,

Charan.

Hi @charankoona ,

In attached Java file, if condition is written in this way –>

if(requestList != null & & !requestList.isEmpty())

Not sure if it is converted by this web page.

Could you please check if AND condition is written is proper or not

Hi Charan,

The issue is
for (Map.Entry set : values.entrySet()) {

requestList.remove(userapp);
}
ConcurrentModificationException You are calling requestList.remove(userapp) while iterating over the same map using a for-each loop. This will throw a ConcurrentModificationException at runtime.

Can you try below code and see if it works

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import sailpoint.api.*;
import sailpoint.object.*;
import java.util.*;
import java.lang.*;
import sailpoint.tools.*;
import java.text.ParseException;

public static Date parseDate(String dateStr) throws ParseException {
  String[] patterns = {
    "M/d/yyyy h:mm:ss a",
    "MM/dd/yyyy hh:mm:ss a"
  };

  for (String pattern : patterns) {
    try {
      SimpleDateFormat sdf = new SimpleDateFormat(pattern);
      sdf.setLenient(false);
      return sdf.parse(dateStr);
    } catch (ParseException ignored) {
    }
  }

  throw new ParseException("Unparseable date: " + dateStr, 0);
}

Custom cust = context.getObjectByName(Custom.class, "CBQ BranchChange custom Object");
Map values = (Map) cust.get("pendingRequest");

//For custom object if there is an issue, you can try below, if the above is not returning properly

//Map values = (Map) cust.getAttributes().get("pendingRequest");


if (values != null && !values.isEmpty()) {

  Iterator iterator = values.entrySet().iterator();

  while (iterator.hasNext()) {
    Map.Entry set = (Map.Entry) iterator.next();

    String userapp = (String) set.getKey();
    Map objectsvalues = (Map) set.getValue();

    String startdateTime = (String) objectsvalues.get("startDateandTime");
    Date startDate = parseDate(startdateTime);
    Date now = new Date();

    long diff = (now.getTime() - startDate.getTime()) / 1000;

    if (diff > -3600) {

      WorkflowLaunch wflaunch = new WorkflowLaunch();
      Workflow wf = context.getObjectByName(Workflow.class, "workflowname");

      wflaunch.setWorkflowName(wf.getName());

      Map launchArgsMap = new HashMap();
      launchArgsMap.put("applicationName", String.valueOf(objectsvalues.get("applicationName")));
      launchArgsMap.put("domainId", String.valueOf(objectsvalues.get("domainId")));
      launchArgsMap.put("branchCode", String.valueOf(objectsvalues.get("branchCode")));
      launchArgsMap.put("oldBranchCode", String.valueOf(objectsvalues.get("oldBranchCode")));
      launchArgsMap.put("startDateandTime", String.valueOf(objectsvalues.get("startDateandTime")));
      launchArgsMap.put("defaultvalues", objectsvalues.get("defaultvalues"));
      launchArgsMap.put("DSMNumber", objectsvalues.get("DSMNumber"));

      wflaunch.setVariables(launchArgsMap);

      Workflower workflower = new Workflower(context);
      WorkflowLaunch launch = workflower.launch(wflaunch);

      // Safe removal during iteration
      iterator.remove();
    }
  }
}

context.saveObject(cust);
context.commitTransaction();