Why are Attachments and Watchers fields not available during issue creation?

Simple answer

Attachments and Watchers are not set at the exact point of issue creation in Jira. In fact, it is done as part of a secondary phase.  By the time this phase happens, the "issue created" issue event has already been fired.

More details

This relates to how JEMH works, creating an issue is a two phase process.  Issue Creation fires a 'created event' but at that time, various custom fields have not been populated.

Prior to 1.7.x, the workaround is to not use ISSUE_CREATED events, but add a custom Event in the JIRA UI, then configure JEMH to fire that custom event.  Of course, this does mean changes to existing work-flows. Sorry about that, no other option.

This issue was logged in our system as JEMH-280.  It was a fairly infrastructural issue, and was fixed in version 1.7.x (requires JIRA 6.4+).  It will not be back-ported to earlier releases.  Attachments and watchers are still handled after the issue is created.  This means that a custom issue creation event is still required when attachments and watchers are to be used in notification.  Interactive issue creation will still require the Event Listener to be configured to notify for the "Issue Created" event, meaning under some use cases, some users may get additional unnecessary notifications.  A solution has been suggested to Atlassian that would allow us to remedy this: https://jira.atlassian.com/browse/JRA-61609



JEMH 1.7 and newer

  1. JEMH receives the email and parses email body

  2. JEMH extracts values from email body

  3. Phase 1

    • Creates the issue with core issue attributes, WITH custom fields, but still WITHOUT watchers or attachments

    • all custom fields are set

    • ISSUE_CREATED fires

  4. The postfunctions of the creating issue event are performing

    • Postfunctions to ISSUE_CREATED now DO HAVE access to custom fields, but DO NOT HAVE access to watchers or attachments

  5. Phase 2

    • watchers added

    • attachments added

    • JEMH fires optional CUSTOM EVENT (its not a workflow step)

  6. Issue Creation is complete

JEMH 1.6 and older

  1. JEMH receives the email and parses email body

  2. JEMH extracts values from email body

  3. Phase 1

    • Creates the issue with core issue attributes, WITHOUT custom fields, watchers or attachments

    • ISSUE_CREATED event fires

  4. The postfunctions of the creating issue event are performing

    • Postfunctions on ISSUE_CREATED DO NOT HAVE access to custom fields as they have not been set yet

  5. Phase 2 - JEMH Issue field population

    • all custom fields are set

    • watchers added

    • attachments added

    • JEMH fires optional CUSTOM EVENT (its not a workflow step)

  6. Issue Creation is complete