Get Listener Event Type from script that executes the listener? (+ generating logs for scripts/http start and end)

I have a script executing in a Start and End execution listener.
Is it possible for the script to determine which listener is being executed? (whether it is a Start or a End Event type).

execution.getEvent() should do the trick.

Found it!

Thanks! @camunda for thinking about this type of stuff!

https://docs.camunda.org/javadoc/camunda-bpm-platform/7.7/org/camunda/bpm/engine/delegate/BaseDelegateExecution.html#getEventName()

execution.getEventName()

and

https://docs.camunda.org/javadoc/camunda-bpm-platform/7.7/constant-values.html#org.camunda.bpm.engine.delegate.ExecutionListener.EVENTNAME_START

1 Like

@thorben where would getEvent come from, vs getEventName

For anyones interest for future use cases.

I needed this because we were logging the Start and End of HTTP requests (and did not want to make changes to HTTP Connector at this time).

so some scripts that basically result in the function call of:

generateLog('This is a message that defaults to log level 1');
generateLog('This is a message that is set at log level 3', 'error');

followed by:


switch (execution.getEventName()) {
  case "start":
    generateLog('Starting HTTP Request');
    break;
  case "end":
    generateLog('Finishing HTTP Request');
    break;
}

which outputs logs such as:

{
    "time": "2017-09-01T14:58:13.876Z",
    "cid": "fe4fc9ef-2f29-45f2-adeb-cfc1982d005d#819485",
    "level": 1,
    "app": "camunda",
    "version": "0.7.0",
    "msg": "Starting HTTP Request",
    "processDefinitionId": "efa6fe80-8f25-11e7-99ac-0242ac110008",
    "processInstanceId": "f9b79815-8f25-11e7-99ac-0242ac110008",
    "processDefinitionName": "Process Request",
    "processDefinitionKey": "ProcessRequest",
    "processParentExecutionId": null,
    "processCurrentActivityName": "Do Something",
    "processCurrentActivityId": "ServiceTask_1010dsd"
}
{
    "time": "2017-09-01T14:58:15.766Z",
    "cid": "fe4fc9ef-2f29-45f2-adeb-cfc1982d005d#819485",
    "level": 1,
    "app": "camunda",
    "version": "0.7.0",
    "msg": "Finishing HTTP Request",
    "processDefinitionId": "efa6fe80-8f25-11e7-99ac-0242ac110008",
    "processInstanceId": "f9b79815-8f25-11e7-99ac-0242ac110008",
    "processDefinitionName": "Process Request",
    "processDefinitionKey": "ProcessRequest",
    "processParentExecutionId": null,
    "processCurrentActivityName": "Do Something",
    "processCurrentActivityId": "ServiceTask_1010dsd"
}

just FYI for anyone in the future.

It’s getEventName, I remembered the wrong name.

1 Like