Rule to fetch scheduled failed tasks

Which IIQ version are you inquiring about?

Version 8.4

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

I am trying to write a rule to send notifications for failed scheduled tasks. So far , this is what I have.

QueryOptions qo = new QueryOptions();
Filter f1 = Filter.and(Filter.notnull(“schedule”),Filter.ne(“type”,“liveReport”);
Filter f2 = Filter.notnull(“completed”);
qo.addFilter(Fitter.and(f1,f2));
Iterator it = context.search(TaskResult.class,qo);

The problem with this though is its bringing taskresults of several unwanted types like “system”, “certification” etc. What would be the best way to do this?

Hi @dk0200,

Have you tried storing the names of the required scheduled task names in a custom object and then using that custom object to query and see if that particular list of scheduled tasks failed?

1 Like

Hi,
I think your having syntax error , you are not closing the and method

1 Like

Hi Diwas,

Is liveReport a custom task? Because I didn’t find a task of this type in the list.
It would be really helpful if you can attach task result from the object browser for your task.

Secon for fetching Failed tasks you should also add a filter stating completionStatus=“Fail”.

Thank you!

1 Like

sorry, its a typo. I dont my work laptop on me so I am typing it out. It is just to give you a gist of my approach.

HI @703hardik ,

I dont have my work laptop . I think I added that filter initially to exclude scheduled reports. Later I realized , there are a lot more than scheduled reports I need to exclude.

Also, I have seen failed task with completion status of both “Error” and “Failed” . I did not want to add another AND filter for these conditions. I am checking for that here:

while (it != null && it.hasNext()) {
         TaskResult tr = (TaskResult) it1.next();
        sailpoint.object.TaskItemDefinition.Type type = tr.getType();
       if(( type != "Certification" && type != "System" && type != "Generic") && tr.getCompletionStatus() != "Success"){
              log.error( tr.getName());
         }
  }
}

Sorry I should have added this in my original post.

Hi @dk0200 ,

I think better approach would be to keep the list of Scheduled tasks you want to monitor in a list or may be in a custom object and then look for completion status as you are change in above code for Success or Error, below are the expected Completion message:

1 Like

not a bad idea but its static. I dont really want to keep updating the code or the object everytime a new task is scheduled.

@dk0200 ,

Apologies for late response, if I understood you right you requirement is to flag any Scheduled task which is not of type Certification/Generic/ and System if it fails. Hope below code helps. This is working:


<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE Rule PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<Rule created="" id="" language="beanshell" modified="" name="Read Failed Scheduled Task">
  <Source>
  import sailpoint.object.TaskResult;
  import sailpoint.object.Filter;
  import sailpoint.object.QueryOptions;

  QueryOptions QO=new QueryOptions();

  Filter filter=Filter.and(Filter.notnull("TaskResult.schedule"),Filter.ne("TaskResult.completionStatus","Success"));

  QO.addFilter(filter);

  Iterator it=context.search(TaskResult.class, QO);

  while (it.hasNext()) {
    TaskResult tr = (TaskResult) it.next();
    sailpoint.object.TaskItemDefinition.Type type = tr.getType();
    if(( type != "Certification" &amp;&amp; type != "System" &amp;&amp; type != "Generic")){
      return ( tr.getName());
    }
  }

  </Source>
</Rule>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.