Removing classification using code

I have this requirement to remove classification on groups.

I am using beanshell code in the Workflow step to add the classification and it’s working fine for me
but while I try to remove them, it gives me unknown null error.

Any suggestion will be appreciated.
Below is the code which I am using to remove classification.

import sailpoint.object.ManagedAttribute;
import sailpoint.object.Classification;
import sailpoint.object.ObjectClassification;

ManagedAttribute ma = context.getObjectByName(ManagedAttribute.class,"example");
if(ma != null ) {
  List<ObjectClassification> objClass = ma.getclassifications();
  for (ObjectClassification objC : objClass){
  System.out.println("ManagedAttribute : "+objC.getId());
  
  
  //System.out.println("removed");
  Boolean re = ma.removeClassification(objC);
  System.out.println(re);
  context.saveObject(ma);
  context.commitTransaction();
  }
}

Can you try saving the Object and Committing the transaction outside the for loop

The issue you are facing is that you are removing objects from the list in a for-loop which brakes the for-loop.
The solution, store what you want to remove in a separate list in the for-loop and start a new for-loop over the separated list to perform the actual removal.

import sailpoint.object.ManagedAttribute;
import sailpoint.object.Classification;
import sailpoint.object.ObjectClassification;

ManagedAttribute ma = context.getObjectByName(ManagedAttribute.class,"example");
if(ma != null ) {
  List<ObjectClassification> objClass = ma.getclassifications();
  List<ObjectClassification> toBeRemoved = new ArrayList();

  for (ObjectClassification objC : objClass) {
    toBeRemoved.add(objC);
  }
  for (ObjectClassification objC : objClass) { 
    ma.removeClassification(objC);
  }
  
  if (log.isDebugEnabled()) log.debug(ma.toXml());
  
  context.saveObject(ma);
  context.commitTransaction();
}

– Remold

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