Archiving a manual work-item

In SailPoint IdentityIQ 8.4, is it possible to programmatically complete and archive a manual work item that was generated directly through code? Since these work items are not associated with an Identity Request or a WorkflowCase.

The work items behave normally in the UI — I can manually complete and archive them without any issues. However, I’m trying to implement a rule to automatically close aging work items from the backend. For that, I need a reliable way to reject and archive these code‑generated work items within a rule.

Has anyone implemented this successfully? Please advise.

@Spoorthy_m You can do this. Can you confirm the type of the work items and how you’re creating them?

Yes, you can mark the finished. Do you have the rule to mark the workitem finished??

Hi @Spoorthy_m

There are two ways to do it.

  1. Set the expiration date during the creation itself Since you are generating the workitem through your code - workItem.setExpiration(date);

  2. you can create a custom rule to reject/expire the workitem after certain period**.**

    WorkItem workItemToApprove = context.getObjectByName(WorkItem.class, workItemName);
    workItemToApprove.setCompleter(“ownerName”);
    workItemToApprove.setState(WorkItem.State.Expired);

    or

    workItemToApprove.setState(WorkItem.State.Rejected);
    context.saveObject(workItemToApprove);
    context.commitTransaction();
    Workflower wf = new Workflower(context);
    wf.finish(workItemToApprove);

Thanks,

Sivaprakash.

@abhi617 I’m creating a manual action work-item. And I’m creating the work-item using context.saveObject(item);

Item variable is of type workItem and has all the attributes set, description and approval set.

@naveenkumar3 Yes, I do have it. But it’s not getting archived after I finish it.

Hi @Spoorthy_m , Welcome to Sailpoint developer forum.

You can complete workitem. @SivaprakashRNTBCI explained various methods to complete workitem.

If you want to have WorkItemArchive object for that workitem, please check global settings which shows type of Workitems can be archived.

If your workitem type is not selected in that list, check if you can select it.

Otherwise, you probably have to write code for archiving it.

Hope this helps.

but are they getting finished??

can you please share the rule here, which you are using please??

@naveenkumar3 @SivaprakashRNTBCI Thank you for your suggestion. I’m writing a similar code, this is finishing the workitem but not archiving it.

@mandarsane Let me try manually archiving it by code. Thanks.

public Workflower wflower = new Workflower(context);
WorkItem wi = context.getObjectById(WorkItem.class, “Id”);
ApprovalSet set = wi.getApprovalSet();
if (null != set)
{
List appItems = set.getItems();
if (null != appItems && appItems.size() > 0)
{
for (ApprovalItem item : appItems)
{
item.reject();
}
}
}
wi.load();
Identity spadmin = context.getObjectByName(Identity.class,“admin”);
String currentOwner = wi.getOwner()!=null? wi.getOwner().getDisplayName():null;
wi.setOwner(spadmin);
wi.setState(WorkItem.State.Finished);
wi.setCompletionComments(“Manual workitem auto-closed by SailPoint Administrator”);
wflower.reject(wi);

can you try below rule, you can add filter as per your requirement. try this code, this should finish the workitem and put them in archive.

can you try below rule and see if it works for you?? Put filter according to your requirement.and also in identity configuration, inside workitems, See if you have selected manual Actions for archival.





Filter filter2 = Filter.eq("owner.name","ownername");
  Filter filter3 = Filter.eq("requester.name","requestname");
  
QueryOptions qp = new QueryOptions();
 
qp.addFilter(Filter.and(filter2,filter3));
  int size=0;
  
  List workitems = context.getObjects(WorkItem.class,qp);
 for(WorkItem wi: workitems)
  {
   if(wi.getType().toString().equalsIgnoreCase("Approval")){
     wi.setCompletionComments("comment if needed");
    
	wi.setCompleter("username");
	wi.setState(WorkItem.State.Finished); 
wi.addComment("Testing"); 
     context.saveObject(wi);
   Workflower flower = new Workflower(context);
flower.process(wi,false); 



	context.commitTransaction();
	context.decache();

	 
   
    
     
	
    size++;
	   

    }
  
  }


@Spoorthy_m You can use the sample code provided by @naveenkumar3 . This should mark your manual work items as completed. But to see them in WorkItemArchive, you need to allow archival in GlobalSettings → IdentityIQ Configuration → Workitems→ Work Item Archives → Select Manual Action, this should allow your manual work items to be stored in WorkItem Archive.
Please also share your code using which you are generating the manual workitems to review what type your are setting and what all attributes are available? This should allow us to recommend necessary filters to be part of the archival rule.

For reference: