Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Count Issue Links

Alex Piwowar April 23, 2020

I need a method to count the number of links that an issue has. I see in the scriptrunner docs that there is numberOfLinks. Can that be used in a scriptrunner script?

 

https://scriptrunner-docs.connect.adaptavist.com/jiracloud/jql-aliases.html#_linked_issues

 

If not, what is the method to loop through links and increase a count?

1 answer

1 accepted

2 votes
Answer accepted
Kristian Walker _Adaptavist_
Community Champion
April 24, 2020

Hi Alexandar,

Thank you for your question.

I can confirm that ScriptRunner for Jira Cloud does not provide any JQL functions to search for how many linked issues an issue has out of the box.

However, I can confirm that it is possible to create a Script Listener which calls the Search API and runs a JQL search to get the required linked issues and then counts the number of these and stores these in a field on the issue that triggered the listener.

I can confirm we have an example in the documentation page located here which shows how to count the number of subtasks on an issue using this approach, and you will be able to use this script as a reference guide to help you create the script that you require.

I hope this information helps.

Regards,

Kristian

Alex Piwowar April 27, 2020

Thanks for your response.

 

Why is the search split up into multiple lines?

def allSubtasks = get("/rest/api/2/search") 
.queryString(
"jql", "parent=${parentKey}")
.queryString(
"fields", "[]")
.asObject(Map)
.body
.issues
as List<Map>
Kristian Walker _Adaptavist_
Community Champion
April 28, 2020

Hi Alexander,

Thank you for your response.

I can confirm the rest call requires all these lines as is the structure that the Atlassian API requires to search for issues in groovy and is split into multiple lines to format it to make it easy to read and understand and to follow good coding practices.

To explain your structure above I can confirm that

  • Line 1 is making the call to the search API.
  • Line 2 is passing the JQL query that you want to pass to run as the search query to return the issues.
  • Line 3 is passing an Array where you can specify what fields you want to return for each issue which is returned by the search passed in line 2.
  • Line 4 specifies that the object returned by the API call is a Map data structure.
  • Line 5 is where we access the main body of the response is accessed.
  • Line 6 is where all of the issues returned are put into a List data structure so that they can be used inside of the logic of the script.

I hope this information helps.

Regards,

Kristian

Suggest an answer

Log in or Sign up to answer