Connecting to Jira Service Management
Jira Service Management receives events through an automation rule that starts with an incoming webhook trigger and creates a work item from the details.
Steps in Jira:
-
Log in to Jira Service Management
-
Select the Settings (cog) icon, then System
-
Select Global automation and then Create flow, either from scratch or from a template
-
If you are starting from scratch, select Incoming webhook in the Add a trigger submenu
-
The next step is choosing which topic events create work items as well as specifying the format/data you will see on each item. Important: When you subscribe to a topic, Electric sends every event in it. A rule that simply creates a work item will create one for each event, whatever its type, and with the same format each time. To give each event its own summary, description, and priority, add a condition for each event type, as described below.
-
Click Condition under Add a step on the right
-
Select IF or ELSE: Add condition options
-
Under Conditions, click + Add condition
-
Select {{smart values}} condition
-
Fill in the condition:
-
First value:
{{webhookData.event_type}} -
Condition: equals
-
Second value: the event you want, for example
employee.created -
Leave Run actions if... on All conditions match, then click Next
-
See the Choosing which events create work items section below to see all the event types available to use as conditions
-
-
Click the Add step button under that IF condition and select the Action step option
-
Select Create a work item
-
Fill out the Space and Issue type you want these work items to be created as
-
The Summary and Description fields will show on default but you can select the Choose fields to set button to add other fields you want to set on the work item. See the Mapping fields into your work item section below to find all the available data for each topic as well as examples of Descriptions to use.
-
-
Click the Add else icon (the branch icon under the + at the bottom of the path). This adds an Else if path. Repeat step c-g for each further event you want to act on
-
Leave out any event you do not want a work item for. If no path matches, nothing is created
-
-
Once you have set up your flow how you want it, click Save without enabling and give your flow a name
-
After you save, click on the Incoming webhook trigger and set the work item criteria to No work items from the webhook. Electric supplies all the data, so the rule does not need to look anything up first
-
Click Generate new secret and then Copy the Webhook URL and Secret
Important: The URL and secret only appear after you save the rule for the first time. If you skip saving, the token will not be active and Jira will reject every delivery.
Need detailed instructions? Atlassian covers the trigger in Configure the incoming webhook trigger and field mapping in Use incoming webhooks with smart values.
Steps in Electric:
-
Log in to Electric
-
Select Settings, then the Webhooks tab
-
Click Create webhook and select Jira Service Management
-
Enter a Name for the webhook
-
Paste the Jira webhook URL into Endpoint URL
-
Paste the Jira secret into Automation webhook token. Electric sends it back to Jira on every delivery
-
Select your topics, leave Active on, and Click Create webhook
-
You are all set!
Choosing which events create work items
The condition for each event is in the table below, so you can copy it straight in.
|
Event |
First value |
Condition |
Second value |
|---|---|---|---|
|
Employee created |
|
Equals |
|
|
Employee updated |
|
Equals |
|
|
Employee offboarded |
|
Equals |
|
|
Employee reactivated |
|
Equals |
|
|
Added to a group |
|
Equals |
|
|
Removed from a group |
|
Equals |
|
|
Group created |
|
Equals |
|
|
Group updated |
|
Equals |
|
|
Group deleted |
|
Equals |
|
|
Task created |
|
Equals |
|
|
Task completed |
|
Equals |
|
|
Task canceled |
|
Equals |
|
|
Task automation failed |
|
Equals |
|
Mapping fields into your work item
In your Create work item action, build the summary and description from the values Electric sends. Below you will see what data is available to select from for each topic as well as example descriptions to use.
Fields on every event
|
Smart value |
What it contains |
|---|---|
|
|
A unique ID for the event. If the same event is ever delivered twice, the ID stays the same |
|
|
The event name. One of: |
|
|
The topic the event belongs to. One of: |
|
|
When the event happened |
|
|
Your Electric organization ID |
|
|
|
Employee lifecycle
Events: employee.created, employee.updated, employee.offboarded, employee.reactivated
|
Smart value |
What it contains |
|---|---|
|
|
The employee's ID in Electric. It stays the same even if their name or email changes |
|
|
The employee's first name |
|
|
The employee's last name |
|
|
The employee's work email |
|
|
The employee's job title |
|
|
The employee's status, for example |
|
|
The start date, or empty text if none is set |
|
|
The IDs of the employee's groups, as comma-separated text |
|
|
On |
Example descriptions, by event
Employee group membership
Events: employee.group_added, employee.group_removed
These events carry everything in the Employee lifecycle table, plus the two fields below. They exist because, after a removal, the group is no longer in the employee's group list, so there would otherwise be no way to tell which group changed. There are no previous_ fields on these events.
|
Smart value |
What it contains |
|---|---|
|
|
The employee's ID in Electric |
|
|
The employee's first name |
|
|
The employee's last name |
|
|
The employee's work email |
|
|
The employee's job title |
|
|
The employee's status, for example |
|
|
The start date, or empty text if none is set |
|
|
The IDs of the employee's groups, as comma-separated text |
|
|
The ID of the group the employee was added to or removed from |
|
|
The name of that group |
Example descriptions, by event
Groups & membership
Events: group.created, group.updated, group.deleted
|
Smart value |
What it contains |
|---|---|
|
|
The group's ID in Electric |
|
|
The group's name |
|
|
The ID of the parent group, or empty text if the group has no parent |
|
|
How many employees are in the group |
|
|
On |
Please note: group.deleted is shorter than the other two. It contains the fields on every event plus {{webhookData.id}} and nothing else, because the group no longer exists by the time the event is sent. If you need the group's name when it is deleted, look it up from the ID in your own records.
Example descriptions, by event
Tasks
Events: request.created, request.completed, request.canceled, request.automation_failed
Remember that the Tasks topic uses request in its field and event names. request.completed and request.canceled can create their own work items, as in the examples below, or update the work item you created for request.created. See Keeping your work items in sync below.
|
Smart value |
What it contains |
|---|---|
|
|
The task's ID in Electric |
|
|
The task's title, for example "Grant access to Slack" |
|
|
The type of task, for example |
|
|
The category the task belongs to, for example |
|
|
What kind of requester raised the task, for example |
|
|
The requester's ID |
|
|
The requester's name |
|
|
The requester's email |
|
|
The assignee's ID, or empty text if the task is unassigned |
|
|
The assignee's name, or empty text |
|
|
The assignee's email, or empty text |
|
|
The ID of the person the task was raised for, or empty text |
|
|
The name of the person the task was raised for, or empty text |
|
|
The email of the person the task was raised for, or empty text |
Example descriptions, by event
Keeping your work items in sync
By default, every event creates a new work item. For events that describe a change to something you already track, you may prefer to update the existing work item instead. Here are two patterns to try.
Comment on an existing work item when an employee is updated
An employee.updated event carries the new values plus a previous_ version of each field that changed. Instead of creating a new work item for every change, your rule can find the work item you created for that employee and add a comment such as "Job title changed from Support Engineer to Software Engineer".
-
When you create the work item for
employee.created, add a label containing the employee's ID, for exampleemployee-{{webhookData.id}}. The ID never changes, even when a name or email does, so it is a reliable way to find the work item again. -
In your
employee.updatedpath, add a Lookup work items action with a JQL search such aslabels = "employee-{{webhookData.id}}". -
Add an Add comment action that describes the change using
{{webhookData.previous_job_title}}and{{webhookData.job_title}}, or{{webhookData.previous_email}}and{{webhookData.email}}.
If you track employees by email instead of ID, previous_email is how you find the original work item after an email change, because the old work item still carries the old address.
Close the loop on tasks
Add a label containing the task ID, such as request-{{webhookData.request_id}}, when you handle request.created. When request.completed or request.canceled arrives, look up the work item by that label, then add a comment or transition it.
Please note: These patterns depend on how your Jira project is set up. Build them with a test event first and confirm the lookup finds the right work item.
Handling fields that are not always filled in
Some values are only there sometimes. An employee may have no job title set, and the previous value of a field is only sent when that field actually changed. On employee.updated, Electric sends the old value as previous_ followed by the field name, for example {{webhookData.previous_job_title}}.
If you reference one of these on an event that does not carry it, the line still appears in your work item with nothing after it. You have two options:
-
Accept the blank line. This is the simplest approach and is usually fine.
-
Show the line only when the value is present. Wrap it in a Jira
ifsmart value. This keeps work items tidy but takes more familiarity with Jira automation.
Show a line only when the value exists
Wrap the line in a Jira if smart value. The line, and its label, appear only when the field has a value:
{{#if(webhookData.job_title)}}Job title: {{webhookData.job_title}}{{/}}
{{#if(webhookData.previous_job_title)}}Previous job title: {{webhookData.previous_job_title}}{{/}}
Tip: Test events always have an empty start_date and group_ids, so they are a handy way to check your condition. Wrap the start date line, send a test event, and confirm that line is missing from the work item:
{{#if(webhookData.start_date)}}Start date: {{webhookData.start_date}}{{/}}
Atlassian documents these in Automation smart values: conditional logic.
Please note: A successful run sometimes displays the created work item twice in the audit log. Only one work item is created.
Using one rule or several
If you subscribe one webhook to several topics, a single rule receives all of them. You have two options:
-
Create a separate webhook and rule for each topic. We recommend this if you are new to Jira automation. Each rule stays simple, and each audit log shows only one kind of event.
-
Use one rule with conditional logic. Add an IF or ELSE: Add condition options on
{{webhookData.event_type}}and set it to equals the event you want to match, for exampleemployee.createdorrequest.created, then add a different action in each path. To match a whole family of events at once, choose starts with and enter the start of the name, for exampleemployee.. This keeps everything in one place but takes more familiarity with Jira automation.
Atlassian describes these comparison options in Jira automation conditions.