Script Studio: Event Triggers

    A script can be configured to run automatically whenever a corresponding change occurs in Jira. Script Studio supports 47 event types across 13 groups, and each script selects the events it responds to.

    Note: 📹 Video placeholder — configuring a script to respond to Issue created, creating an issue in Jira, and reviewing the resulting execution.

    1. Configuration

    1. Select the script in the file tree.
    2. In the Properties panel, open the Events row.
    3. Select the events the script should respond to. Changes are saved immediately.
    4. Set Enabled to True in the Properties panel.

    Note: A script does not run until Enabled is set to True, regardless of how many events have been selected. The event selection screen displays a reminder while this is the case.

    2. The event selection screen

    image-20260830-213440.png

    The screen lists the complete catalogue, arranged in groups, and provides:

    • a search field for locating an event by name;
    • All and None options for each group;
    • a Clear all option and a running count of the events selected;
    • the Jira event name beneath each entry, for reference against the Atlassian documentation.

    3. The event catalogue

    GroupEvents
    IssueCreated, updated, deleted
    Issue linkCreated, deleted
    CommentCreated, updated, deleted
    AttachmentCreated, deleted
    WorklogCreated, updated, deleted
    ProjectCreated, updated, archived, deleted
    Issue typeCreated, updated, deleted
    VersionCreated, updated, deleted, released, unreleased, moved
    SprintCreated, updated, started, closed, deleted
    BoardCreated, updated, deleted, configuration changed
    UserCreated, updated, deleted
    FilterCreated, updated, deleted
    OptionsSite-wide configuration settings, such as voting, watching and time tracking

    Advanced: the relationship to Jira events

    Several entries in the catalogue correspond to the same underlying Jira event. The creation and the editing of a comment are both delivered as avi:jira:commented:issue, and the site configuration settings are all delivered as avi:jira:changed:configuration with differing property keys. Script Studio distinguishes between them, so that selecting Comment updated results in the script running only when a comment is edited.

    4. Information available to the script

    A script started by an event receives the details of that event through context.event.

    PropertyContents
    event.keyThe catalogue identifier, for example issue.created
    event.typeThe Jira event name, for example avi:jira:created:issue
    event.subjectA short description of what changed, such as an issue key
    event.payloadThe complete event data supplied by Jira
    /**
     * Assigns newly created high-priority work to the person currently on duty.
     */
    import { jira } from 'jira-api';
    
    const ON_DUTY: Record<string, string> = {
      Highest: '5b10a2844c20165700ede21g',
      High: '5b10a2844c20165700ede21g'
    };
    
    export default async function run(_getIssue, context: ScriptContext) {
      const created = context.event.payload.issue;
      if (!created || !created.key) return null;
    
      if (created.fields?.assignee) {
        console.log(`${created.key} is already assigned`);
        return null;
      }
    
      const priority = created.fields?.priority?.name || '';
      const accountId = ON_DUTY[priority];
      if (!accountId) {
        console.log(`${created.key} has priority ${priority || 'none'}; no action taken`);
        return null;
      }
    
      await jira.put('/rest/api/3/issue/{issueIdOrKey}/assignee', {
        path: { issueIdOrKey: created.key },
        body: { accountId }
      });
    
      console.log(`${created.key} (${priority}) assigned to ${accountId}`);
      return accountId;
    }
    

    5. Delivery behaviour

    The following characteristics should be taken into account when writing a script that responds to events.

    BehaviourConsequence
    An event may be delivered more than onceThe script should be safe to run twice for the same change. Verify the current state before acting, rather than assuming the change has not already been handled.
    Delivery may be delayedEvents can arrive some time after the change. Where the decision depends on the current state, read the issue again rather than relying on the event data.
    Changes made by Script Studio are excludedA script that modifies an issue is not started again by its own change.
    Every execution is recordedSuccessful and failed executions alike appear in the run history, and a failure is indicated in the file tree.

    6. Restricting when a script acts

    Event selection applies to the whole site. Any further condition — a particular project, issue type or field — is expressed within the script.

    export default async function run(_getIssue, context: ScriptContext) {
      const issue = context.event.payload.issue;
    
      // Restrict to a single project
      if (!String(issue?.key || '').startsWith('SUP-')) return null;
    
      // Act only when the status has actually changed
      const changed = context.event.payload.changelog?.items || [];
      if (!changed.some((item) => item.field === 'status')) return null;
    
      // …
    }
    

    7. Troubleshooting

    SymptomAction
    The script never runsCheck that Enabled is set to True in the Properties panel. This is the most frequent cause.
    The script runs but takes no actionThe script is returning early. Add output before each condition and review the run history.
    The script runs for issues it should ignoreAdd the relevant condition within the script, as shown above.
    The script runs twice for one changeExpected behaviour. Ensure the script is safe to run twice.
    The script runs later than expectedExpected behaviour. Where timing is critical, use a workflow post function instead.
    The file tree shows a failure indicatorOpen the run history from the Properties panel to review the error.
    Removing the last event disabled the scriptExpected behaviour. A script with neither a schedule nor an event has no means of running.

    Related pages