Get start time of Delegate Execution

Hi,

DelegateExecution does not have method like getStartTime() so Im trying to get start time of subprocess from HistoryService in notify() method. Im doing this at process start with parse listener but it gives error like down below.

Cannot invoke “org.camunda.bpm.engine.history.HistoricProcessInstance.getStartTime()” because the return value of “org.camunda.bpm.engine.history.HistoricProcessInstanceQuery.singleResult()” is null

delegateExecution.getProcessInstanceId() is not returning null and here is my code:

 @Override
    public void notify(DelegateExecution delegateExecution) throws Exception {
        if (delegateExecution.getSuperExecution() != null) {

				Date startTime = historyService.createHistoricProcessInstanceQuery()
    		    .processInstanceId(delegateExecution.getProcessInstanceId())
    		    .singleResult()
    		    .getStartTime();
	   
        	
        } else {
        	
        }
    }

Thanks for any help.

Hello @Mert_Mahanoglu ,

above query will not work if you do not have history data saved to the tables.

Please make sure you have an async before on the element the listener is attached to.

Jonathan

1 Like

Hi @jonathan.lukas,

Thanks for your reply and after select “async before” option on start element of call activity, start time data successfully returning.

1 Like

Is this the time when the job was created? Or the time when its execution really started (by the job executor)? Whatever it is: how can I retrieve the other value (time)?

getStartTime() returns time when the instance started. You can think of it as the “Start Time” value below.

If you want to format or parse time value u can use methods like down below.

Date startTime = historyService.createHistoricProcessInstanceQuery()
							.processInstanceId(delegateExecution.getProcessInstanceId())
							.singleResult().getStartTime();
String createdOnUTC = Instant.parse(startTime.toInstant().toString())
	    		.atOffset(ZoneOffset.UTC)
	    		.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSSS"));
	        	startTime.getTime();
1 Like

My question was about a job that is “in the middle of a process”. For the first job of the process, the two values are the same. But a job that is in the middle is created first and then picked up by the job executor. I wanted to have both values.