Auto approved to approval assignment rule is creating approval workitem

Which IIQ version are you inquiring about?

8.5p2

Please share any images or screenshots, if relevant.

Please share any other relevant files that may be required (for example, logs).

import sailpoint.object.Workflow.Approval;
  import sailpoint.object.Identity;
  import sailpoint.object.ApprovalItem;
  import sailpoint.object.ApprovalSet;
  import sailpoint.object.WorkItem;
  import sailpoint.tools.Util;
  import sailpoint.object.Comment;


  import org.apache.logging.log4j.LogManager;
  import org.apache.logging.log4j.Logger;
  import org.apache.logging.log4j.Level;


  Identity targetUser = context.getObjectByName(Identity.class, identityName);
  List nApprovals = new ArrayList();
  List comments = new ArrayList();
  comments.add(new Comment("Auto Approved", "spadmin"));


  for (Approval approval : approvals) {
    c_log.debug("Processing approval for user: " + targetUser.getName());
    ApprovalSet approvalSet = approval.getApprovalSet();
    c_log.debug("Approval set: " + approvalSet.toXml());

    List items = approvalSet.getItems();
    //List itemsToRemove = new ArrayList();

    for (ApprovalItem item : items) {
      String itemDisplayValue = item.getDisplayableValue();
      String appName = item.getApplicationName();
      String itemname = item.getName();

      if (itemDisplayValue.equalsIgnoreCase("XXXXX")) {
        item.setState(WorkItem.State.Finished);
        item.setComments(comments);
        item.setOwner("spadmin");
          //itemsToRemove.add(item);
        } else {
        c_log.debug("No Auto approval");
      }
    }

    /*
            // If all items are auto-approved, skip this approval entirely
            if (itemsToRemove.size() == items.size()) {
                c_log.debug("All items auto-approved. Skipping approval.");
                continue;
            }

            // Remove auto-approved items from approval set
            if (!Util.isEmpty(itemsToRemove)) {
                for (ApprovalItem curritem : itemsToRemove) {
                    approvalSet.remove(curritem);
                }
                c_log.debug("Removed " + itemsToRemove.size() + " auto-approved items.");
            }
            */

    approval.setApprovalSet(approvalSet);
    c_log.debug("Approval after processing: " + approval.toXml());
    nApprovals.add(approval);
  }

  return nApprovals;

Share all details about your problem, including any error messages you may have received.

*I am using approval assignment rule to approve certain entitlements automatically. As per the logic, I am marking the item state to “Finished” and also adding comments, which is happening perfectly fine (Please refer to the screenshot). however, there is a approval workitem being created, which shouldn’t as the item is already approved.
I am using approvalScheme as “manager” and the approval workitem is for manager.

How can I stop creation of this approval?
Any suggestions are realy appreciated.*

@soswain_resmed Your workitem is getting generated first and then you are changing the state to Finished. that’s why you see a workitem. You need not to generate the Approval object if it is satisfying your auto approval criteria.

@soswain_resmed One thing to try it out, your commented-out block was already correct. Uncomment it: set Finished + comments for the audit, remove the auto-approved items from the approval set, and if nothing is left for a review, continue so that Approval is never added to nApprovals. An Approval that’s never returned produces no work item. The reason you still see one is that your live code keeps every Approval with the manager owner.

Hello Soumyakanta. I think the work item is still getting created because the manager Approval is being returned even after you mark the item as Finished.

I would handle it in two places.

First, for the manager approval, mark the item approved, remove it from that ApprovalSet, and only add the Approval back if something still needs manager approval.

List nApprovals = new ArrayList();

for (Approval approval : approvals) {

    ApprovalSet currentSet = approval.getApprovalSet();

    if (currentSet == null) {
        nApprovals.add(approval);
        continue;
    }

    List itemsToRemove = new ArrayList();

    for (ApprovalItem item : currentSet.getItems()) {

        if ("XXXXX".equalsIgnoreCase(item.getDisplayableValue())) {
            item.approve();
            item.setState(WorkItem.State.Finished);
            itemsToRemove.add(item);
        }
    }

    for (ApprovalItem item : itemsToRemove) {
        currentSet.remove(item);
    }

    if (!Util.isEmpty(currentSet.getItems())) {
        approval.setApprovalSet(currentSet);
        nApprovals.add(approval);
    }
}

Then I would also apply the same condition to the main approvalSet:

if (approvalSet != null && !Util.isEmpty(approvalSet.getItems())) {

    for (ApprovalItem item : approvalSet.getItems()) {

        if ("XXXXX".equalsIgnoreCase(item.getDisplayableValue())) {
            item.approve();
            item.setState(WorkItem.State.Finished);
        }
    }
}

The second part is worth keeping. In a similar ApprovalAssignment case, an auto-approved-only request did not generate provisioning until the items in the master approvalSet were also marked approved: ApprovalAssignment rule not working for specific use case

I would test it once with only the auto-approved entitlement and once with a mixed request. In the mixed case, only the normal item should reach the manager.

Thanks @neel193 @punna0001 .

As suggested by @punna0001 , the second part is required to meet the requirement.

@punna0001 @neel193

I am seeing a strange behaviour with approval assignment rule.
I have set my approvalScheme to “manage, owner”, but with approval assignment rule, where I put my logic to auto approve or skip approval for certain scenarios, which is working fine, howver, for other scenarioes, it just sending approval to manager and once approved, it going for privsioning. There is no owner approval is being triggered.

It’s working as expected without the approval assignment rule.

Can you please suggest, whether I am missing anything?

Thanks,
Sam

If approval assignment rule is available in the workflow it becomes authoritative, meaning the approvals returned from the rule are final, they are considered the only approvals and they take precedence.

They are not combined with the system (approvalscheme based) generated approvals. Implementer should take that into account to merge the existing approvals or generate new approvals or ignore the existing approvals and return the complete list of approvals.

So if the approval assignment rule is just returning manager approval in the list, then it’s working expected, provided that both manager and owner approval are being generated in the same step, if they are being split then it’s a different scenario.

I suspect the rule is affecting the owner approval. SailPoint’s Rules in IdentityIQ guide confirms that the rule’s returned approvals list determines the final approvals.

I would temporarily replace the rule body with return approvals; and test a normal and a mixed request. If both stages work, check:

  1. Returned approvals: Ensure non-matching approvals, including child approvals, are preserved. Our earlier logic may exclude approvals whose ApprovalSet is empty.
  2. Master approvalSet: Verify that marking matching items Finished does not prematurely complete items requiring owner approval. This only applies to matching items, so it would not explain a request with nothing auto-approved.

I would compare the input and returned approvals, getChildren(), and item states after manager approval.

Thanks @punna0001 @BhuvaneshGeddam for your suggestions.
The approval was getting skiped, as I was not evaluating the child approvals. The issue is resolved now.

@BhuvaneshGeddam To your input, I am using approvalsplit point and that’s making the approval assignment rule to be evaluated separately for each level of approval.

With some changes to the existing logic, I am able to achieve the required approvals.