high speed issue linking in Jira Service Desk2
November 22, 2018

Automate creating new linked issues in Jira Service Desk

PF
Phill Fox 5 minute read

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.

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

tables 35

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.

table 42

Set the fields behaviour

Add an initialiser with the following code:

import com.atlassian.Jira.component.ComponentAccessor
  
  def issueManager = ComponentAccessor.getIssueManager()
//Check to make sure this is the correct context for the behaviour.
if (getBehaviourContextId() == "create-Problem")
  {
//Set the project and issuetype to be readonly so the user cannot alter these.
     getFieldById("project-field").setReadOnly(true)
     getFieldById("issuetype-field").setReadOnly(true)
  
//Find the details of the Issue from which the request to link was made
     def contextIssue = issueManager.getIssueObject(getContextIssueId())
  
//Pre-populate the Summary, issue link and issue link type.
     getFieldById("summary").setFormValue("Problem created from ${contextIssue.key}").setReadOnly(false)
     getFieldById("issuelinks-linktype").setFormValue("Problem for Incident").setReadOnly(true)
     getFieldById("issuelinks-issues").setFormValue(contextIssue.key).setReadOnly(true)
  }

You can change the default content for the Summary by altering the line:

getFieldById("summary").setFormValue("Problem created from ${contextIssue.key}").setReadOnly(false)

If we break this down into its constituent parts we can understand what each part does.

table 37

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

table 38

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

table 40

Add a new mapping

table 43

Set the fields behaviour

Add an initialiser with the following code to create and pre-populate the issue type:

import com.atlassian.Jira.component.ComponentAccessor
  
def issueManager = ComponentAccessor.getIssueManager()
//Check to make sure this is the correct context for the behaviour.
if (getBehaviourContextId() == "create-remedy")
  {
//Set the project and issuetype to be readonly so the user cannot alter these.
     getFieldById("project-field").setReadOnly(true)
     getFieldById("issuetype-field").setReadOnly(true)
  
//Find the details of the Issue from which the request to link was made
     def contextIssue = issueManager.getIssueObject(getContextIssueId())
  
//Pre-populate the Summary, issue link and issue link type.
     getFieldById("summary").setFormValue("Remedial Action created from ${contextIssue.key}").setReadOnly(false)
     getFieldById("issuelinks-linktype").setFormValue("Remedial Action of").setReadOnly(true)
     getFieldById("issuelinks-issues").setFormValue(contextIssue.key).setReadOnly(true)
  }

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

table 45

What does it look like?

Now we have added two new options to the operations menu we should see something similar to this screenshot.

image2017 11 27 13 45 10

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.

Like this blog? Why not share it on social media and check out our post on ScriptRunner for Jira Service Desk to learn how ScriptRunner can help you get more out of your Jira Service Desk instances.

Don't have ScriptRunner for Jira yet?

Start your free trial