Search This Blog

Friday, June 5, 2020

Customizing SailPoint Task Definitions - Run with Response

Subject: Batch Processing in SailPoint

Regarding: Adding responses to a batch process using Run Rule

Creating a TaskDefinition for running a rule is normally performed by the following:

Setup -> Tasks
New Task -> Run Rule

Enter the details such as what you want the rule to be named, description, then the rule to be executed.  Save and Run


Once you have done this, you will have a framework TaskDefinition with the following elements:

<Attributes>
  <Map>
    <entry key="ruleName" value="the rule you chose"/>
  </Map>
</Attributes>

and also:

<Parent>
  <Reference class="sailpoint.object.TaskDefinition" name="Run Rule"/>
</Parent>

You may want to output some results.  The issue with this is that the Run Rule normally does not have a section for outputs.

To fix this you can add the following elements:

<Signature>
  <Returns>
    <Argument name="totalCount" type="int">
      <Prompt>Total users processed</Prompt>
    </Argument>
    <Argument name="resultString" type="string">
      <Prompt>Results:</Prompt>
    </Argument>
  </Returns>
</Signature>

You also can add this to a clone of Run Rule and use that as a template for new rules.  But this does not populate the values.
 
To populate the values, the following is needed in the rule:
 
 (imports)
import sailpoint.tools.Message;
import sailpoint.tools.Message.Type;
import sailpoint.object.Attributes;
import sailpoint.object.TaskResult;
import sailpoint.object.TaskResult.CompletionStatus;

variables:
int resultCount=0;
String resultString="";

Set these values in your code.

Then just before the return:

if(taskResult!=void) {
  taskResult.addMessage(new Message(Message.Type.Info,"Completed Successfully", null));
  Attributes resultAttr=new Attributes();
  resultAttr.put("totalCount",new Integer(resultCount));
  resultAttr.put("resultString",resultString);
  taskResult.setAttributes(resultAttr);
  taskResult.setCompletionStatus(TaskResult.CompletionStatus.Success);
}

I use a StringBuffer instead of concatenating the resultString, and then set resultString to the toString() result of the StringBuffer.


Inputs:

If you want to add inputs to the Run Rule task definition, you would need to start by pulling the signature inputs from Run Rule.  From there you can add fields as you would any TaskDefinition.

For example:

<Signature>
  <Inputs>
    <Argument helpKey="help_task_run_rule_rule" name="ruleName" required="true" type="Rule">
      <Prompt>label_rule</Prompt>
    </Argument>
    <Argument helpKey="help_task_run_rule_ruleconfig" name="ruleConfig" type="string">
      <Prompt>label_rule_config</Prompt>
    </Argument>
    <Argument helpKey="Enter action to be taken" name="action" type="string">
      <Prompt>Action</Prompt>
    </Argument>
  </Inputs>
</Signature>

In the rule you can use the following code to check for action:

String actionStr=null;
if(config.containsKey("action"))
  actionStr=config.get("action");
}

then later you can check the value of actionStr
If nothing was entered the value will not be in config



No comments:

Post a Comment