Search code examples
bpmncamunda

Can i access the value of the timer event in camunda?


As I can set the duration of a timer event, can i access it through a java code? or as a camunda variable?


Solution

  • If you want to access the attribute as defined in the XML, you can use the BPMN Model API. For example:

    String processDefinitionId = ...
    String timerEventId = ...
    
    BpmnModelInstance bpmnModel = repositoryService.getBpmnModelInstance(processDefinitionId);
    CatchEvent timerEvent = bpmnModel.getModelElementById(timerEventId);
    TimerEventDefinition timerEventDefinition = 
      (TimerEventDefinition) timerEvent.getEventDefinitions().iterator().next();
    TimeDuration duration = timerEventDefinition.getTimeDuration();
    String configuredDuration = duration.getTextContent();
    

    If you want to get the actual time at which the timer fires the next time at runtime, you'll have to query for the respective job:

    String processDefinitionId = ...
    String timerEventId = ...
    String processInstanceId = ...
    
    Job timerJob = managementService.createJobQuery()
      .processDefinitionId(processDefinitionId)
      .activityId(activityId)
      .processInstanceId(processInstanceId)
      .singleResult();
    Date firingDate = timerJob.getDueDate();
    

    Note that timerJob is null if the process instance you query for has not yet reached the timer event.