Which IIQ version are you inquiring about?
Version 8.3
Please share any images or screenshots, if relevant.
Share all details related to your problem, including any error messages you may have received.
I need task examined count from scheduled task which are executed as mentioned in screenshot attached file.
ref: How can I get all scheduled task which have already runed in task result via rule - #4 by iamksatish
kjakubiak
(Kamil Jakubiak)
2
You can just extract this information from the task results - like that
import sailpoint.object.TaskResult;
TaskResult taskResult = context.getObject(TaskResult.class, "Refresh Identity Cube");
return taskResult.getAttributes().get("total");
Of course it’s simple example for single task but you can just make it more generic if you need by iterating through task results.
1 Like
iamksatish
(Satish Kurasala)
3
@amanKsingh
Add the below code, you will see the output of task Result Attributes as well
Updated code along with Task Result attributes
import java.util.ArrayList;
import java.util.Calendar;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Iterator;
import sailpoint.object.TaskResult;
import sailpoint.object.TaskDefinition;
import sailpoint.object.TaskSchedule;
import sailpoint.object.TaskResult.CompletionStatus;
import sailpoint.object.QueryOptions;
import sailpoint.object.Filter;
import sailpoint.tools.Util;
import org.quartz.CronExpression;
import java.text.ParseException;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.Duration;
public String getRunInterval(String cronExpressionString){
CronExpression cronExpression = new CronExpression(cronExpressionString);
Date nextValidTime1 = cronExpression.getNextValidTimeAfter(new Date()); // Get the next valid time after the current time
Date nextValidTime2 = cronExpression.getNextValidTimeAfter(nextValidTime1); // Get the next valid time after the first next valid time
long intervalInMillis = nextValidTime2.getTime() - nextValidTime1.getTime(); // Calculate the interval in milliseconds
long intervalInMinutes = intervalInMillis / (60 * 1000);
long intervalInHours = intervalInMillis / (60 * 60 * 1000);
String intervalString;
if (intervalInHours > 0) {
intervalString = intervalInHours + " hours";
} else {
intervalString = intervalInMinutes + " minutes";
}
System.out.println("Interval between two runs: " + intervalString);
return intervalString;
}
public String runTimeforTaskResult(String taskResultID){
String runTime="NA";
TaskResult taskResultObj=context.getObjectById(TaskResult.class, taskResultID);
Date completionDate=taskResultObj.getCompleted();
Date launchDate=taskResultObj.getLaunched();
if(completionDate!=null){
LocalDateTime dateTime1 = LocalDateTime.ofInstant(launchDate.toInstant(), ZoneId.systemDefault());
LocalDateTime dateTime2 = LocalDateTime.ofInstant(completionDate.toInstant(), ZoneId.systemDefault());
Duration duration = Duration.between(dateTime1, dateTime2);
long totalSeconds = duration.getSeconds();
long hours = totalSeconds / 3600;
long minutes = (totalSeconds % 3600) / 60;
long seconds = totalSeconds % 60;
runTime = hours + " hours " + minutes + " minutes " + seconds + " seconds";
}
return runTime;
}
QueryOptions qo=new QueryOptions();
qo.addFilter(Filter.notnull("id"));
List taskScheduleList = context.getObjects(TaskSchedule.class,qo);
Map taskScheduleOutput=new HashMap();
for(TaskSchedule taskSchedule: taskScheduleList){
String taskScheduleName=taskSchedule.getName();
String cronExp= taskSchedule.getCronExpression(0);
String scheduleInterval="";
if(Util.isNotNullOrEmpty(cronExp)){
scheduleInterval=getRunInterval(cronExp);
}
String defintionName=taskSchedule.getDefinitionName();
Date lastExecutionTime=taskSchedule.getLastExecution();
Date nextEexuctionTime=taskSchedule.getNextExecution();
String lastExecDate="";
String nextExecDate="";
if(lastExecutionTime!=null)
{
SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
lastExecDate = formatter.format(lastExecutionTime);
}
if(nextEexuctionTime!=null)
{
SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
nextExecDate = formatter.format(nextEexuctionTime);
}
TaskResult taskResultObj=taskSchedule.getLatestResult();
String lastRunStatus="";
String lastRunTime="";
String taslkResultAttr="";
if(taskResultObj!=null){
lastRunTime=runTimeforTaskResult(taskResultObj.getId());
lastRunStatus=taskResultObj.getCompletionStatus().toString();
if(taskResultObj.getAttributes()!=null){
taslkResultAttr=taskResultObj.getAttributes().toString();
}
}
Map taskResultMap=new HashMap();
taskResultMap.put("task Defintion Name",defintionName);
taskResultMap.put("Last Execution Time",lastExecDate);
taskResultMap.put("Next Execution Time",nextExecDate);
taskResultMap.put("Last Execution Status",lastRunStatus);
taskResultMap.put("Last Execution Duration",lastRunTime);
taskResultMap.put("Schedule Interval",scheduleInterval);
taskResultMap.put("Task Result Attributes",taslkResultAttr);
taskScheduleOutput.put(taskScheduleName,taskResultMap);
}
return taskScheduleOutput;
Example
<entry key="Check expired work items daily">
<value>
<Map>
<entry key="Last Execution Duration" value="0 hours 0 minutes 7 seconds"/>
<entry key="Last Execution Status" value="Success"/>
<entry key="Last Execution Time" value="20-05-2024 00:00:00"/>
<entry key="Next Execution Time" value="21-05-2024 00:00:00"/>
<entry key="Schedule Interval" value="24 hours"/>
<entry key="Task Result Attributes" value="{expirations=0, reminders=0, escalations=0, total=0, emailsSuppressed=0, totalWorkItems=0, totalCertItems=0, pushes=0}"/>
<entry key="task Defintion Name" value="Check Expired Work Items"/>
</Map>
</value>
</entry>
1 Like
system
(system)
Closed
4
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.