Filter concatenation

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.

Hello all,

I am trying to write a filter to fetch scheduled task results that have failed. This is what I have:

QueryOptions qo1 = new QueryOptions();
Filter f1 = Filter.notnull("schedule");
Filter f2 = Filter.or(Filter.eq("completionStatus","failed"),Filter.eq("completionStatus","error");
qo1.addFilter(Filter.and(f1,f2));

Upon testing, I am getting all the failed task results. It almost looks like f1 is not being evaluated. What am I doing wrong here? what should I be doing ?
TIA

Hi @dk0200

I tested your code in my environment and its working as expected.
The closing parentheses is missing in your above code for filter f2, idk if you forgot to put it here during copy paste.

QueryOptions qo1 = new QueryOptions();
Filter f1 = Filter.notnull("schedule");
Filter f2 = Filter.or(Filter.eq("completionStatus","failed"),Filter.eq("completionStatus","error"));
qo1.addFilter(Filter.and(f1,f2));
return (context.countObjects(TaskResult.class,qo1));

I got the expected count.

sorry, I missed that while pasting here. That is strange. I am getting all the failed task results (scheduled and ad hocs). Are you sure you are only getting scheduled task results?

@dk0200

I am sure.

that is strange. not sure , why its not working on my end.

@dk0200

is it possible for you to paste the code here?
I would like to help.

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE Rule PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<Rule created="1706895103475" id="0aaead448d611001818d6ae055f222cb" language="beanshell" modified="1706903365477" name="Detect Failed Scheduled Tasks Rule" significantModified="1706903365477">
<Source>
    import sailpoint.object.TaskResult;
    import sailpoint.api.SailPointContext;
    import java.util.List;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.Map;
    import sailpoint.object.EmailOptions;
    import sailpoint.object.QueryOptions;
    import sailpoint.object.Filter;
  	import sailpoint.object.EmailTemplate;
		QueryOptions qo1 = new QueryOptions();
  	       Filter f1 = Filter.notnull("schedule");
  	       Filter f2 = Filter.or(Filter.eq("completionStatus","failed"),Filter.eq("completionStatus","error"));
               qo1.addFilter(Filter.and(f2,f1));
		Iterator it1 = context.search(TaskResult.class, qo1);
		
  	while (it1 != null &amp;&amp; it1.hasNext()) {
      TaskResult tr1 = (TaskResult) it1.next();
      log.error("Failed Scheduled Tasks Name " + tr1.getName());
      
    }
</Source>
</Rule>

Just checked your code, try below


Map test = new HashMap();
QueryOptions qo1 = new QueryOptions(); 
Filter f1 = Filter.notnull("schedule"); 
Filter f2 = Filter.or(Filter.eq("completionStatus","failed"),Filter.eq("completionStatus","Error")); 
qo1.addFilter(Filter.and(f2,f1)); 
Iterator it1 = context.search(TaskResult.class, qo1);
while (it1 != null &amp;&amp; it1.hasNext()) {
  TaskResult tr1 = (TaskResult) it1.next();
  log.error("Failed Scheduled Tasks Name " + tr1.getName());  
  test.put(tr1.getName(), tr1.getSchedule());
}
return test;

In my lab, it’s giving only failed Scheduled TaskResult. In above code you will get schedule name also in map.

pls try

@dk0200

Your code should work!!
Are you sure about getting all the failed task result

thanks for your response. your code is not very different from mine, only thing different is the map. So I am kind of baffled as to why I am getting a different result from all of you.

positive. I am getting 518 results back.

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