I need to trigger leaver workflow if related identity is found.
import sailpoint.api.*;
import sailpoint.object.*;
import sailpoint.tools.*;
import java.util.*;
List inactiveStatuses = Arrays.asList("terminated", "disabled", "retired");
Filter pamFilter = Filter.eq("subWorkerType", "PAM");
QueryOptions qo = new QueryOptions();
qo.addFilter(pamFilter);
Iterator pamIdentities = context.search(Identity.class, qo);
while (pamIdentities.hasNext()) {
Identity pam = pamIdentities.next();
String pamName = pam.getName();
if (pamName == null || !pamName.endsWith("PIM")) continue;
String baseName = pamName.substring(0, pamName.length() - 3);
Identity base = context.getObjectByName(Identity.class, baseName);
if (base == null) continue;
String status = base.getAttribute("workerStatus");
if (status == null) continue;
status = status.toLowerCase();
if (inactiveStatuses.contains(status)) {
pam.setAttribute("workerStatus", "Terminated");
context.saveObject(pam);
}
}
context.commitTransaction();
in this (inactiveStatuses.contains(status)) {
pam.setAttribute(“workerStatus”, “Terminated”);
context.saveObject(pam);
}
rather than setting attribute i need to trigger Leaver workflow
Is this identity trigger rule that you have mentioned or a rule that will be triggered using a rule runner task. You have not mentioned how you are executing this code. In case of identity trigger rule you just need to return true to trigger the workflow.
If this is a rule that you will be executing using a task then you will need to schedule workflow using RequestManager as shown in sample below for each matching identity for which you want to trigger the workflow:
String workflowName = "YOUR WORKFLOW NAME";
String caseName = "YOUR WORKFLOW CASE NAME";
String launcher ="spadmin";
Workflow eventWorkflow = context.getObject(Workflow.class, workflowName);
if (null == eventWorkflow) {
log.error("Could not find a workflow named: " + workflowName);
throw new GeneralException("Invalid worklfow: " + workflowName);
}
// Simulate the request being submitted by a user. Default: spadmin.
Identity id = context.getObjectByName(Identity.class, launcher);
if (null == id) {
log.error("Could not find a requester Identity: " + launcher);
throw new GeneralException("Invalid identity: " + launcher);
}
// Build out a map of arguments to pass to the Request Scheduler.
Attributes reqArgs = new Attributes();
reqArgs.put(StandardWorkflowHandler.ARG_REQUEST_DEFINITION,
sailpoint.request.WorkflowRequestExecutor.DEFINITION_NAME);
reqArgs.put(sailpoint.workflow.StandardWorkflowHandler.ARG_WORKFLOW,
workflowName);
reqArgs.put(sailpoint.workflow.StandardWorkflowHandler.ARG_REQUEST_NAME,
caseName);
reqArgs.put( "requestName", caseName );
// Build a map of arguments to pass to the Workflow case when it launches.
Attributes wfArgs = new Attributes();
wfArgs.put("identityName", pamName );
wfArgs.put("launcher", launcher);
wfArgs.put("appName", "Active Directory");
wfArgs.put("workflow", eventWorkflow.getName());
wfArgs.put("eventTag", caseName);
reqArgs.putAll(wfArgs);
// Use the Request Launcher to schedule the workflow reqeust. This requires
// a Request object to store the properties of the request item.
Request req = new Request();
RequestDefinition reqdef = context.getObject(RequestDefinition.class, "Workflow Request");
req.setDefinition(reqdef);
Calendar cal = Calendar.getInstance();
long launchTime = cal.getTimeInMillis();
req.setEventDate( new Date( launchTime ) );
req.setOwner(id);
req.setName(caseName);
req.setAttributes( reqdef, reqArgs );
// Schedule the work flow via the request manager.
RequestManager.addRequest(context, req);
1 Like
Hi @autorun6464 ,
I’ve used other times the following code to call directly our Leaver Workflow, which only requieres two variables, the Identity object and the name of your workflow:
public Date xMin(int days, int min){
long today = (long) (new Date().getTime());
long newDate = today ;
if(days== 0){
newDate = today + min*60*1000;
}else{
newDate = today + days*24*60*60*1000;
}
Date dateR= new Date(newDate );
return dateR;
}
Identity id = context.getObjectByName(Identity.class, "378493");
//Termination identity event
RequestDefinition reqDef = context.getObjectByName(RequestDefinition.class, "Workflow Request");
Request event = new Request();
event.setDefinition(reqDef);
event.setOwner(id);
event.addAttribute("workflow"," RapidSetup Leaver"); //Enter here the name of you Leaver Workflow
event.addAttribute("identityName", id.getName());
event.addAttribute("isTerminateIdentity", true);
event.setName("Evento Baja Certificacion "+ id.getName());
event.setNextLaunch(xMin(0, 10)); //Use this in case you don't want to launch the termination inmediately and would prefer in 10 minutes or whatever
context.saveObject(event);
context.commitTransaction();
Hope this helps!
Let me know if you have any questions.
1 Like
Really appreciate guys it worked . just had to add couple more arguments it is triggering workflow now. Thank you @SanjeevIAM and @angelborrego for your help