Approval for deleting Account

Want to send approval (as of now i m sending approval to random users of the deleting identity’s department) when i m deleting a account.
Below is the code plz do the needfull correction in this:
import sailpoint.object.;
import sailpoint.api.
;
import sailpoint.tools.;
import java.util.
;
import ProvisioningPlan.*;

log.error(“Executing SelectTwoRandomUsersFromDepartment Rule”);

// Obtain SailPoint context
SailPointContext context = sailpoint.api.SailPointFactory.getCurrentContext();

// Fetch the current provisioning plan
//Map args = context.getArguments();

if (args == null) {
log.error(“Args map is null. Rule execution stopped.”);
return null;
}
ProvisioningPlan plan = getArgs(“plan”);
if (plan == null) {
log.error(“No provisioning plan provided.”);
return null;
}

// Check if there is an AccountRequest for Active Directory with DELETE operation
boolean isDeleteOperation = false;
for (AccountRequest acctReq : plan.getAccountRequests()) {
if (“Active Directory”.equals(acctReq.getApplication()) &&
AccountRequest.Operation.Delete.equals(acctReq.getOperation())) {
isDeleteOperation = true;
break;
}
}

if (!isDeleteOperation) {
log.error(“Skipping rule execution as the operation is not DELETE.”);
return null;
}

// Fetch the current identity
Identity currentIdentity = context.getObject(Identity.class, plan.getIdentity());
if (currentIdentity == null) {
log.error(“Current identity not found.”);
return null;
}

log.error("Current identity: " + currentIdentity.getName());

// Fetch all links for the identity and find AD account
List links = currentIdentity.getLinks();
Link adAccount = null;
for (Link link : links) {
if (“Active Directory”.equals(link.getApplicationName())) {
adAccount = link;
break;
}
}

if (adAccount == null) {
log.error("AD account not found for identity: " + currentIdentity.getName());
return null;
}

log.error("AD account found for identity: " + currentIdentity.getName());

// Retrieve department from AD account
String departmentName = adAccount.getAttribute(“department”);
if (Util.isEmpty(departmentName)) {
log.error("Department name is missing for identity: " + currentIdentity.getName());
return null;
}

// Query identities in the same department
QueryOptions qo = new QueryOptions();
qo.addFilter(Filter.eq(“department”, departmentName));

List identityList = new ArrayList();
Iterator iterator = context.search(Identity.class, qo);
while (iterator.hasNext()) {
Identity identity = iterator.next();
if (!identity.getName().equals(currentIdentity.getName())) {
identityList.add(identity);
}
}

log.error(“Total identities found in department '” + departmentName + "': " + identityList.size());

// Ensure at least two identities exist
if (identityList.size() < 2) {
log.error("Not enough identities found in department: " + departmentName);
return null;
}

// Shuffle and select two random identities
Collections.shuffle(identityList);
Identity selectedIdentity1 = identityList.get(0);
Identity selectedIdentity2 = identityList.get(1);

log.error("Selected identity 1: " + selectedIdentity1.getName());
log.error("Selected identity 2: " + selectedIdentity2.getName());

// Return the selected identities for approval workflow
List selectedIdentities = new ArrayList();
selectedIdentities.add(selectedIdentity1.getName());
selectedIdentities.add(selectedIdentity2.getName());

log.error("Selected identities: " + selectedIdentities);

return selectedIdentities;

Please revert back me the correct code.

what correction you are looking for. I do not see any code in this which is sending approval , its looking for some users and then selecting randomly 2 users and what’s its doing with those is not clear in this code. do you want this for all users..?

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