Programmatically Approving a request via API

Which IIQ version are you inquiring about?

Version 8.1

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

I am trying to iterate ApprovalItems and programmatically approve certain ones.
the test code below seems to update but not approve. the approval still shows up in the ui.

public void findAllApprovalWorkitems() throws Exception {
        QueryOptions qo = null;
        try {
            this.context = this.getContext();
            qo = new QueryOptions();
            Filter filter = Filter.eq("type", "Approval");
            qo.addFilter(filter);
            Iterator it = context.search(WorkItem.class, qo);
            if (it == null) {
                System.out.println("ERROR:No Records");
                return;
            }
            while (it.hasNext()) {
                Object obj = it.next();
                WorkItem wi = (WorkItem) obj;
                String scheme = (String) wi.getAttribute("approvalScheme");
                System.out.println("scheme:" + scheme);
                ApprovalSet approvals = wi.getApprovalSet();

                List<ApprovalItem> approvalItems = approvals.getItems();
                for (ApprovalItem ai : approvalItems) {
                    System.out.println("Approver:" + ai.getAccountDisplayName());
                    System.out.println("Approver:" + ai.getApplicationName());
                    System.out.println("Approver:" + ai.getAssignmentId());
                    System.out.println("Approver:" + ai.getApprover());
                    System.out.println("Approver:" + ai.getAttributes());
                    System.out.println("Approver:" + ai.isApproved());
                    ai.approve();
                    System.out.println("Approver:" + ai.isApproved());
                }
                wi.setApprovalSet(approvals);
                context.saveObject(wi);
                context.commitTransaction();
            }
        } catch (Exception e) {
            System.out.println("ERROR:" + e.getMessage());
            e.printStackTrace();
            throw e;
        }

    }

not sure if this is getting formatted :frowning:
Thanks in advance

Hi @vmasih ,

You need to set the WorkItem to finish. Add the following line just before context.saveObject(wi); :

wi.setState(WorkItem.State.Finished);

– Remold

Hi Remold,

Added that line and it’s still sitting in the UI waiting for approval.

Thanks for the assist!!

Did you run the ‘Perform Maintenance’-task to process the approval?

— Remold

Yep just tried that. it’s still waiting for approval.

the ApprovalWorkItemService manages to do it but it seems to do a lot more than what I am trying especially the completion part

Thanks again.

Can you test with the following statement added after the commitTransaction:

wi.getHandlerInstance().handleWorkItem(context, wi, true);

Javadoc WorkItemHandler:

handleWorkItem(SailPointContext con, WorkItem item, boolean foreground)
Called by the system after a modification to the work item has been stored.

– Remold

2 Likes

Yep that did it!!!

excellent, thanks for all you help!!! on a sunday!!

Vishal

1 Like

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