Automate creating new linked issues in Jira Service Desk

In this blog we will look at how to quickly create a new linked Problem ticket based on the current Incident/Alert. You will recall in the previous blog, we learnt how to quickly create a link to an existing Problem ticket . However, sometimes the and this covers the scenario where the Problem ticket may does not yet exist.

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

NameDescription
Problem Issue CreationThe behaviour to be taken when a Problem Issue is to be created from an existing Incident/Alert

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.
Behaviour IDRemedial Action Issue Creation
Issue TypesAll Issue Types
Choose Project<Select as appropriate>

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.

ScriptWhat does it identify
getFieldById("summary")Which field to pre-populate (Summary)

There may be others you would also wish to pre-populate and you can add additional lines similar to this.
setFormValue(“ “)The action to apply which is to set the form value to the contents
"Problem created from ${contextIssue.key}"Static text followed by the dynamic content to include the original issue key
setReadOnly(false)Allow the user to change the content on creation

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

SectionContent
Note

An optional note, used only for your reference.
Create Problem button
What section should this go in

The section to place the item
Operations-top-level
Key

The key of the module
create-problem
Menu text

Text of menu item
Create Problem
Weight

Placement of the item within its section
1
Condition
Condition to be met before the web fragment is displayed
JiraHelper.project?.key in [""] && 
issue.issueType.name in ["Incident","Alert"]
Project

Create issue in what project
Select the named project in which the Issues are to be created.
Issue TypeProblem

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

NameDescription
Remedial Action
Issue Creation
The behaviour to be taken when a Remedial Action Issue is to be created from an existing Incident/Alert/Problem.

Add a new mapping

Behaviour IDRemedial Action Issue Creation
Issue TypesAll Issue Types
Choose Project<Select as appropriate>

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 dialog

SectionContent
Note

An optional note, used only for your reference.
Create Remedial Action button
What section should this go in

The section to place the item
Operations-top-level
Key

The key of the module
create-remedy
Menu text

Text of menu item
Create Remedial Action
Weight

Placement of the item within its section
1
Condition

Condition to be met before the web fragment is displayed
JiraHelper.project?.key in [""] &&issue.issueType.name in ["Incident","Alert","Problem"]
Project

Create issue in what project
Select the named project in which the Issues are to be created.
Issue TypeProblem

What does it look like?

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

How to automate new linked issue creation in 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.

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 a free trial and see what it can do for your Jira Service Desk automation, integration and management.