Getting name of task in a rule

Which IIQ version are you inquiring about?

IdentityIQ 8.4

Please share any images or screenshots, if relevant.


Share all details about your problem, including any error messages you may have received.

I have a Run Rule Task calling “TEST ABC Rule”. In my rule is there any method I can get the name of the Task that is running the rule (i.e. TEST ABC)?

Hi and Hello,

If i good understand you.
Yes, in SailPoint’s IdentityIQ, you can retrieve the name of the task that is executing a rule by accessing the context object within the rule. This context object contains details about the task, and you can extract the task name from it.

Quick example:

import sailpoint.object.Task;
import sailpoint.object.TaskDefinition;
import sailpoint.api.SailPointContext;

// Assuming you have access to the context object in your rule
SailPointContext context = (SailPointContext) args.get("context");

// Get the task object
Task task = context.getTask();

// Check if task is not null
if (task != null) {
    String taskName = task.getName();  // This will give you the name of the task
    System.out.println("The task running this rule is: " + taskName);
} else {
    System.out.println("No task is currently running.");
}

Regards,
Adam

1 Like

Hi Adam,

How do I know if I have access to the context object in the rule?

Thanks!

You could access the TaskDefinition object from the context:

TaskDefinition taskDef = context.getObjectByName(TaskDefinition.class,"TEST ABC");

Hi @AdamVentum ,

There is no getTask() method in the SailPointContext. Also there is no Task object. You could access the task configuration using TaskDefinition object.

Hi Zeel,

I am looking for a dynamic way to get the name of the Task running the rule is there any possibility on this?
TaskDefinition taskDef = context.getObjectByName(TaskDefinition.class,"TEST ABC");

I still have to hardcode the Object name (i.e. “TEST ABC”).

I don’t know if that is possible.

Could I ask why do you want to keep it dynamic?

Because we would want to add some conditional statements to our rule and depending on which conditional statement is true, the rule would be executed on different applications.

Okay so same Rule being referred in different TaskDefinitions ?

Yes, that is correct. Multiple TaskDefinition but only 1 same rule being referenced in all of the Task.

I don’t think you would be able to achieve this. You would need to create separate rules for each TaskDefinition.

FYI

There is way to pass the arguments to the Rule from TaskDefinition, but this is not the answer for your question as you still need to refer to the TaskDefinition by hard coding the name.

Reference: IdentityIQ run rule task input field of a different type

You can use “taskResult” variable available to the rule associated with the task.
you need not to initialize the variable, Its available by default.

1 Like

@nareshchennuri

Just use the below line in your rule , you will have the parent task that actually triggered the rule

String taskDefName=taskResult.getDefinition().getName();

I dont think taskResult is available by default. Becaus ein my case I Sailpoint gave me this error when I added he below line in my rule

  import sailpoint.object.*;
  
  String taskDefName=taskResult.getDefinition().getName();
  return taskDefName;
import sailpoint.api.IdentityService;   import sailpoint.api.Provisioner;      i . . . '' : Typed variable declaration : Attempt to resolve method: getDefinition() on undefined variable or class name: taskResult : at Line: 14 : in file: inline evaluation of: ``import sailpoint.api.IdentityService;   import sailpoint.api.Provisioner;      i . . . '' : taskResult .getDefinition ( ) 
 BSF info: