Streamline a service desk with JIRA automation
Tags: jira, automation, productivity
Published: 2022-01-17 12:22:38

At [Potloc](https://www.potloc.com/) our service desk is dedicated for the operation teams where they can open a ticket for a bug or a service request. The more our web application grows, the more maintenance it requires. As a result we’ve seen a growing number of tickets pertaining to the same project.

## The need

We wanted a way to link these tickets together to gather additional context.

- Were there any issues on this project in the past?
- What was the solution?
- Which developer worked on it?

These questions can be crucial in getting the visibility required when it comes to debugging.

## The solution

One word: `Automation`

This aptly named feature  allows you to automate  tasks through a  series of actions triggered by specific events.

Let’s link all created tickets for the same project using automation.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6npcw2ihkqzeyjtsirnr.png)

## The how

In our particular case the event is `When a new issue is created` . The entry point for grouping tickets by a specific project is the url field. Each request has a link to easily locate the issue. In 99% of case our url will have the ID of a project. So the first action that you need to process after the creation of an issue is to scan the URL  in order to extract the project ID.

**1. Extract the survey ID**

You can have a hidden field that is not displayed to the user but will allow you to store the extracted ID.
Let's add a `New component` > `New action` > `Edit an issue` and the field you want to use. For the purpose of this article we will use `Root cause`.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rb23lvyssg0j203c0mjw.png)

Above we are using `Smart values`, according to Jira [documentation](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-issues/):

> Smart values allow you to access issue data within Jira. For example, you can use the following smart values to send a Slack message that includes the issue key and issue summary: `{{issue.key}} {{issue.summary}}`
> 

`customfield_10364`: is the ID for our URL field that contains the project ID. You can go to settings or inspect your input to find it.

`substringBetween`: is a [built-in function](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/) that returns the text between the given parameters.

From this moment your field will contain the ID. But to have an up to date flow (with the extracted ID) we have to refetch the data issue by adding a new action `Re-fetch data issue.`

Next, we would like to link issues with the same project ID.

**2. Find linked issues**

Jira has an action for this called Lookup issues.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lvcgxdvxqy7lfw62r6jj.png)

`cf[10359]` : is the identifier of our `Root cause` field (replace the number with your ID)

`issue.customfield_10359` : is the identifier of the `Root cause` field for the other issues

`issueKey != "issue.key"` : we exclude our current issue of the lookup

> :warning: Careful! Your fields will be named differently according to your need.

What we do, in pseudo code, is basically searching via `JQL` if the extracted ID of the issue matches any previously-created issues. We also ensure we exclude the current issue of the search.

*Note: In our context, Root cause is a text field. It's likely that you have to find another operator if the type of your field is different.*

**3. Link similar issues**

Finally, we need to link all results from our previous query with our current issue using the `Link issue to action`.

That's it. From now on you should see previously-created tickets for this project on all your tickets.

Here’s the final result:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zzc2svacas4682tdvjz1.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r3gwfdrl1ne0b4nwibmp.png)

*Pro tips: You could add a condition as a guard clause to stop the automation if the Lookup issues actions does not return anything.*

Happy automation. :tada:

Interested in what we do at [Potloc](https://www.potloc.com/)? Come join us! We are [hiring](https://jobs.lever.co/Potloc) 🚀