Skip to main content
Automate creating new linked issues in Jira Service Management
Share on socials
Illustration of a Jira kanban board
Phill Fox
Phill Fox
22nd November, 2018
Jira

Automate creating new linked issues in Jira Service Management

In this blog, we will look at how to quickly create a new linked Problem ticket for an ongoing incident/alert.
This is the fourth in our Incident Management blog series aimed at making your Incident resolution quicker and your customers happier. In this blog, we will look at how to quickly create a new linked Problem ticket based on the current Incident/Alert. In the previous blog, we learnt how to quickly create a link to an existing Problem ticket.
Using standard Jira functionality, you can clone an existing issue, edit the contents, move the issue to the Problem issue type, and add a link - but all of this is time consuming and requires you to remember the key of the original ticket to create the link as the end.
So, in this tip you will learn how to add an extra action to your operations menu, which helps you complete this action easily as a single action. The The approach taken here is to call the Create Issue dialogue box and to pre-populate it with key information from the Incident or Alert that we are triaging including the link to the current ticket.
Recommend:

Recap of what we already have

  • A set of suitable issue types – Incident and Alerts for capturing occurrences; Problem for the underlying problem resolution; Remedial Action for any corrective actions.
  • Links to describe the relationship between the different Issue Types.

The solution

There are two steps to implementing this tip - the first part is to create a behaviour and then to add a script fragment to increase the options in the operations menu. We have used the operations menu as this is linked to each issue but you could just as easily choose other locations for this new action to be displayed.
You will find the controls for your behaviours at <yourhost>/secure/admin/Behaviours!default.jspa.
The following steps will take you through the creation of your first behaviour. There are three parts to this:
  1. Add a new behaviour
  2. Map the behaviour
  3. Set the behaviour for the fields

Add the new behaviour

Screenshot of adding new behaviour

Add a new mapping

In order for our behaviour to be applied we need to map this to both Issue Types and Projects. For the purpose of this example we are allowing the behaviour on all Issue Types but you might restrict this.
Screenshot of adding new mapping

Set the fields behaviour

Add an initialiser with the following code:
1import com.atlassian.Jira.component.ComponentAccessor
2def issueManager = ComponentAccessor.getIssueManager() 
3//Check to make sure this is the correct context for the behaviour. 
4if (getBehaviourContextId() == "create-Problem") 
5{ 
6//Set the project and issuetype to be readonly so the user cannot alter these.
7getFieldById("project-field").setReadOnly(true)
8getFieldById("issuetype-field").setReadOnly(true)
9
10//Find the details of the Issue from which the request to link was made 
11def contextIssue = issueManager.getIssueObject(getContextIssueId()) 
12
13//Pre-populate the Summary, issue link and issue link type. 
14getFieldById("summary").setFormValue("Problem created from 
15${contextIssue.key}").setReadOnly(false) 
16getFieldById("issuelinks-linktype").setFormValue("Problem for Incident").setReadOnly(true) 
17getFieldById("issuelinks-issues").setFormValue(contextIssue.key).setReadOnly(true) 
18}
You can change the default content for the Summary by altering the line:
1getFieldById("summary").setFormValue("Problem created from
2${contextIssue.key}").setReadOnly(false)
If we break this down into its constituent parts we can understand what each part does.
script descriptions

Add a Script Fragment

Now that we have defined the behaviour, we need to use this behaviour. You will find the section to manage your fragments at:
<yourhost>/plugins/servlet/scriptrunner/builtin?section=fragments.
As we defined a behaviour for a context in the previous section, we now want to add a call to this behaviour from the web interface. To achieve this, use the option to create a "Constrained create issue dialog":

Constrained create issue dialog

Constrained create issue dialog
Once this is implemented, it is time to check that this functions as you expect.

Remedial actions

Now that we have checked this through, we can repeat a similar set of actions to create a similar option for the Remedial Actions.

Add the new behaviour

Screenshot of the remedial action issue creation

Add a new mapping

Screenshot of the remedial action new mapping

Set the fields behaviour

Add an initialiser with the following code to create and pre-populate the issue type:
1import com.atlassian.Jira.component.ComponentAccessor 
2
3def issueManager = ComponentAccessor.getIssueManager()
4
5//Check to make sure this is the correct context for the behaviour.
6if (getBehaviourContextId() == "create-remedy") 
7{
8//Set the project and issuetype to be readonly so the user cannot alter these. 
9getFieldById("project-field").setReadOnly(true) 
10getFieldById("issuetype-field").setReadOnly(true) 
11
12//Find the details of the Issue from which the request to link was made 
13def contextIssue = issueManager.getIssueObject(getContextIssueId()) 
14
15//Pre-populate the Summary, issue link and issue link type.
16getFieldById("summary").setFormValue("Remedial Action created from 
17${contextIssue.key}").setReadOnly(false) 
18getFieldById("issuelinks-linktype").setFormValue("Remedial Action of").setReadOnly(true)
19getFieldById("issuelinks-issues").setFormValue(contextIssue.key).setReadOnly(true) 
20}

Add a Script Fragment

Once again, we add this as a script fragment at:
/plugins/servlet/scriptrunner/builtin?section=fragments
Now we use the "constrained create issue" option again:

Constrained create issue dialogue

Screenshot of constrained create issue dialogue

What does it look like?

Now we have added two new options to the operations menu we should see something similar to this screenshot.
Screenshot of Jira
Now we're starting to establish several shortcuts to make our day-to-day operations simpler and more efficient. Our next tip will look at how we can manage escalation notifications to ensure that people are alerted in a timely way.

Don't have ScriptRunner for Jira yet?

Try ScriptRunner for free with a 30 day trial.
Like this blog? Why not share it on social media.