How to get all policies by owned by an identity and then change them

Which IIQ version are you inquiring about?

8.3

I’m writing a workflow for people leaving, and I need to get all the policies the own and reassign them to someone else. For getting the policies, I have:

          QueryOptions qo = new QueryOptions();
          qo.setCloneResults(true);
          qo.addFilter(Filter.eq("ownerId", id.getId()));
          Iterator policies = context.search(Policy.class, qo);

But I don’t know how to change the owner. An AccountRequest seems wrong.

You will need to use setOwner method available on Policy Object to change the owner followed by saving object and committing transaction using SailPointContext methods.

If you want to take a shortcut and have Policy in the reassignArtifacts section of the leaver or terminate RapidSetup config, this method should take care of it all for you (of course, it will also reassign all of the other object types in the list too): sailpoint.workflow.RapidSetupLibrary.reassignOwnership(WorkflowContext wfc)

But depending on what you’re trying to achieve with your workflow, it might be possible for you to just use the RapidSetup Leaver or immediate termination workflow with a few customizations instead of writing a brand new one yourself.

1 Like

Is there a way to do this through a provisioning plan?

We’ve been having endless trouble with leaver, most probably due to our flakey environment (2 reboots a day!), so for now I’m trying to do this in a workflow which I call from a lifecycle event. Given how much customized behaviour business side has asked for, I suspect using the leaver’s convenience methods will never be an option.

Hi @AJGibson76 ,

Before the Build Plan step in the workflow, add an additional step to reassign the policy to the new owner.
Include the script provided below in that workflow step to perform the reassignment.

int recordCounter = 0;
Identity id = context.getObjectByName(Identity.class,identityName);
Identity newOwner = id.getManager();
QueryOptions qp = new QueryOptions();
qp.addFilter(Filter.eq(owner.name,id.getName()));
qp.setCloneResults(true);

Iterator iterator = context.search(Policy.class,qp);
while(iterator.hasNext()){
recordCounter++;
Policy policy = iterator.next();
policy.setOwner(newOwner);
context.saveObject(policy);
if(0 == (recordCounter % 10)){
context.commitTransaction();
}

}
context.commitTransaction();