TaskStatistics functions get unexpected return codes for running jobs

Document ID : KB000103996
Last Modified Date : 17/07/2018
Show Technical Document Details
Issue:
When evaluating a running job, the functions for the TaskStatistics class returns null-results instead of the expected values. 

Sample code (where "result" is a StatisticSearchItem object):

System.out.println("Return Code: " + result.getReturnCode()); 
System.out.println("Status Code: " + result.getStatusCode()); 
System.out.println("Status Text: " + result.getStatusText());  
System.out.println("State: " + result.getState()); 

Expected Result:

Return Code: 0
Status Code: 1550
Status Text: Still Active
State: state_active (or something similar)

Actual Result:
 
Return Code: 0
Status Code: -1
Status Text: null
State: state_unknown
 
Cause:
It is by design that the "get" functions deliver unknown results for objects that are currently active. The functions will only return meaningful results after the statistic values are available (after the run finishes). 
Resolution:
Use the TaskList Class instead of the TaskStatistics Class. 

Sample code:

int runId = 1234567; 
TaskList tStats = new TaskList(new TaskFilter()); 
//look in statistics also 
tStats.includeHistoricalData(); 
tStats.setRunID(runId); 
uc4.sendRequestAndWait(tStats); 
if (tStats.getMessageBox()!=null) { 
System.out.println("Error: "+tStats.getMessageBox()); 
System.exit(1);

System.out.println("Size: " + tStats.size()); 
if (tStats.size() > 0) { 
Task task = tStats.iterator().next(); 
System.out.println("RunID: " + task.getRunID()); 
System.out.println("Return Code: " + task.getReturnCode()); 
System.out.println("Status Code: " + task.getStatusCode()); 
System.out.println("Status Text: " + task.getStatusText());