Workflows Launched from Custom Tasks

You can launch workflows from a custom task in IdentityIQ. Because tasks are compiled java classes, the custom task must be written as a Java method.

To create a workflow from a custom task:

  1. Create a WorkflowLaunch object in the Java method.

  2. Populate the object with the data the workflow requires.

  3. Use the Workflower class to launch the workflow.

It is often necessary for one workflow to launch another workflow. This can be performed in Beanshell using code similar to the previous example. However, using the workflow library method <i>scheduleWorkflowEvent</i> is easier. Not only does this method launch a workflow, it also allows you to delay the launch until a time in the future.

To have one workflow to launch another workflow, create a step and select scheduleWorkflowEvent as the action. This method requires the following arguments:

Copy
               import java.util.HashMap;
               import sailpoint.api.sailpointContext;
               import sailpoint.api.Workflower;
               import sailpoint.integration.ProvisioningPlan;
               import sailpoint.integration.ProvisioningPlan.AccountRequest;
               import sailpoint.integration.ProvisioningPlan.AttributeRequest;
               import sailpoint.object.Identity;
               import sailpoint.object.Workflow;
               import sailpoint.object.WorkflowLaunch;
               import sailpoint.tools.GeneralException;
               import sailpoint.tools.xml.XMLObjectFactory;
    
 
               HashMap launchArgsMap = new HashMap();
 
               String myIdentityName = "T339222";
              Identity myIdentity = context.getObjectByName(Identity.class, myIdentityName);
 
               //Create Provisioning Plan and add needed attribute values
               ProvisioningPlan plan = new ProvisioningPlan();
               plan.setIdentity(myIdentity);
               AccountRequest accountRequest = new AccountRequest();
               AttributeRequest attributeRequest = new AttributeRequest();
               
               accountRequest.setApplication("IIQ");
               accountRequest.setNativeIdentity(wbIdentity);
               accountRequest.setOperation("Modify");

               attributeRequest.setOperation("Add");
               attributeRequest.setName("assignedRoles");
               attributeRequest.setValue("Benefits Clerk");

               accountRequest.add(attributeRequest);
               plan.add(accountRequest);
               
               //Add needed Workflow Launch Variables to map of name/value pairs 
               launchArgsMap.put("allowRequestsWithViolations","true");
               launchArgsMap.put("approvalMode","parallelPoll");
               launchArgsMap.put("approvalScheme","worldbank");
               launchArgsMap.put("approvalSet","");
               launchArgsMap.put("doRefresh","");
               launchArgsMap.put("enableRetryRequest","false");
               launchArgsMap.put("fallbackApprover","admin");
               launchArgsMap.put("flow","RolesRequest");
               launchArgsMap.put("foregroundProvisioning","true");
               launchArgsMap.put("identityDisplayName","John.Smith");
               launchArgsMap.put("identityName","John.Smith");
               launchArgsMap.put("identityRequestId","");
               launchArgsMap.put("launcher","admin");
               launchArgsMap.put("notificationScheme","user,requester");
               launchArgsMap.put("optimisticProvisioning","false");
               launchArgsMap.put("plan",plan);
               launchArgsMap.put("policiesToCheck","");
               launchArgsMap.put("policyScheme","continue");
               launchArgsMap.put("policyViolations","");
               launchArgsMap.put("project","");
               launchArgsMap.put("requireViolationReviewComments","true");
               launchArgsMap.put("securityOfficerName","");
               launchArgsMap.put("sessionOwner","admin");
               launchArgsMap.put("source","LCM");
               launchArgsMap.put("trace","true");
               launchArgsMap.put("violationReviewDecision","");
               launchArgsMap.put("workItemComments","");
                              
               sailpoint.object.ProvisioningPlan spPlan = new sailpoint.object.ProvisioningPlan();
               spPlan.fromMap(plan.toMap());
               launchArgsMap.put("plan", spPlan);
        
               //Create WorkflowLaunch and set values
               WorkflowLaunch wflaunch = new WorkflowLaunch();
               Workflow wf = (Workflow) context.getObjectByName(Workflow.class,"myWorkflowName");
               wflaunch.setWorkflowName(wf.getName());
               wflaunch.setWorkflowRef(wf.getName());
               wflaunch.setCaseName("LCM Provisioning");
               wflaunch.setVariables(launchArgsMap);
 
               
               //Create Workflower and launch workflow from WorkflowLaunch
               Workflower workflower = new Workflower(context);
               WorkflowLaunch launch = workflower.launch(wflaunch);

               // print workflowcase ID (example only; might not want to do this in the task)
               String workFlowId = launch.getWorkflowCase().getId();
               System.out.println("workFlowId: "+workFlowId);