Launch Workflow via Rule

I have a rule that creates plan based on the identity attributes and runs periodically. I want to launch a custom workflow which is similar to LCM provisioning. Can I get a reference script to launch that workflow via the rule and take the provisioning plan I created.

You can create a rule like this:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE Rule PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<Rule language="beanshell" name="Run java class with workflow">
    <Source>
        return PermanentLeaverHandler.executeWorkflows();
    </Source>
</Rule>

and define this kind of method:

protected void executeWorkflows() throws GeneralException {
        final Workflower workflower = new Workflower(_context);

        for (final WorkflowLaunch workflowLaunch : _workflowLaunches) {
            log().info("Launching " + workflowLaunch.getCaseName());
            workflower.launch(workflowLaunch);
        }
    }

if you need more detailed logic you can read this code that builds WorkflowLaunch:

 public static WorkflowLaunch getWorkflowLauncher(Identity identity, String workflowName, Map<String, Object> launchMap) throws GeneralException {
        final WorkflowLaunch workflowLaunch = new WorkflowLaunch();
        final Workflow       workflow       = SailPointFactory.getCurrentContext().getObjectByName(Workflow.class, workflowName);


        if (workflow != null) {
            workflowLaunch.setWorkflowName(workflow.getName());
            workflowLaunch.setWorkflowRef(workflow.getName());
            workflowLaunch.setCaseName(workflowName + " on Identity: " + identity.getId() + " with name "
                    + identity.getDisplayName());
            workflowLaunch.setVariables(launchMap);
        } else {
            log.error("ERROR: could not find Workflow: " + workflowName);
        }
        return workflowLaunch;
    }

If you have more questions regarding the code feel free to ask but I think it is a good start to move forward with your issue :slight_smile:

2 Likes

Hi,

Assuming that you have created a plan successfully and added account request to the plan. U can use the code below as a sample:

if (!plan.getAccountRequests().isEmpty()) {
                // Launch LCM Provisioning Workflow
                Workflow lcmWorkflow = context.getObjectByName(Workflow.class, "LCM Provisioning");
                if (lcmWorkflow != null) {
                    Attributes args = new Attributes();
                    args.put("identityName", identityName);
                    args.put("launcher", launcher);
                    args.put("requester", launcher);
                    args.put("plan", plan);
                    args.put("workflow", lcmWorkflow.getId());
                    args.put("approvalScheme", "none");
                    args.put("notificationScheme", "none");
                    args.put("doRefresh", "true");

                    WorkflowLaunch wfLaunch = new WorkflowLaunch();
                    wfLaunch.setWorkflowName(lcmWorkflow.getName());
                    wfLaunch.setVariables(args);
                    wfLaunch.setLauncher("spadmin");

                    Workflower workflower = new Workflower(context);
                    workflower.launch(wfLaunch);

                    log.info("LCM Provisioning Workflow launched for identity: " + identityName);
                }

This will launch the LCM provisioning workflow without approval and without email template.

You can mention the workflow you wanted launch and customize based on your requirements.

Workflow lcmWorkflow = context.getObjectByName(Workflow.class, "LCM Provisioning");
1 Like