i want to send the approval when requester request to reset the pswd and approval will send to 2 random users of requester’s department .
This is code which is working fine in some system but in some system it is not.
and giving JAX-RS EXPECTATION .
import sailpoint.object.;
import sailpoint.api.;
import sailpoint.tools.GeneralException;
import sailpoint.object.QueryOptions;
import sailpoint.tools.Util;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
// Log start of execution
log.info(“Executing SelectTwoRandomFromDepartment Rule”);
// Obtain context from SailPoint IIQ
SailPointContext context = sailpoint.api.SailPointFactory.getCurrentContext();
log.error("The context is "+context);
// Fetch the current identity
Identity currentIdentity = context.getObject(Identity.class, identityName);
log.error("The currentIdentity is "+currentIdentity);
if (currentIdentity == null) {
log.error(“Current identity not found.”);
return null;
}
log.error("Current identity found: " + currentIdentity.getName());
// Fetch all links for the identity and find AD account
List links = currentIdentity.getLinks();
log.error("The links are " + links);
Link adAccount = null;
for (Iterator it = links.iterator(); it.hasNext();) {
Link link = (Link) it.next();
if ("Active Directory".equals(link.getApplicationName())) {
adAccount = link;
break;
}
}
log.error("the Account info of adAccount " +adAccount);
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 the department attribute from the AD account
String departmentName = adAccount.getAttribute("department");
log.error("Department Name from AD account: " + departmentName);
if (Util.isEmpty(departmentName)) {
log.error("Department name is missing for identity: " + currentIdentity.getName());
return null;
}
// Query identities based on department
List identityList = new ArrayList();
QueryOptions qo = new QueryOptions();
qo.addFilter(Filter.eq("department", departmentName));
Iterator iterator = context.search(Identity.class, qo);
while (iterator.hasNext()) {
//identityList.add(iterator.next());
Identity identity = iterator.next();
// Ensure current identity is not included in the selection
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 the list
//Collections.shuffle(identityList);
log.error("Shuffling : " +Collections.shuffle(identityList));
Identity selectedIdentity1 = context.getObject(Identity.class, identityList.get(0).getName());
Identity selectedIdentity2 = context.getObject(Identity.class, identityList.get(1).getName());
log.error("Selected identity 1: " + selectedIdentity1.getName());
log.error("Selected identity 2: " + selectedIdentity2.getName());
// Return directly the selected Identity objects
//return selectedIdentity1.getName();
//testing
List selectedIdentities = new ArrayList();
selectedIdentities.add(selectedIdentity1.getName());
selectedIdentities.add(selectedIdentity2.getName());
log.error("Selected identities: " + selectedIdentities);
return selectedIdentities;
Please do the necessary req.