Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How traverse through a List and count the number of items matching a particular string

Doug Levitt
Contributor
October 24, 2021

Hi,

I am looking to figure out how to traverse through a list (in this case, "issuelinks" and:

a) Count the total number of inward links

b) Count the number of inward links that have a status of done

I know how to:

- Count the # of inward links, using:

{{issue.issuelinks.inwardIssue.size}}

- Identify the status of each inward link, using:

{{#issue.issuelinks.inwardIssue.fields.status}}{{name}}{{/}}

- Determine if that status of an inward link is Done using; {{#issue.issuelinks.inwardIssue.fields.status}}{{name.equals(“Done”)}}{{/}}

But, I am unable to figure out how to count the # that are not Done.  Ultimately, I want to set counters (custom fields) with following values: Count of Incoming Links that are Open, Count of Incoming Links that are Done and display these in Jira Dashboards.

Any ideas?

Thanks,

Doug

 

 

1 answer

1 accepted

0 votes
Answer accepted
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 25, 2021

Hi @Doug Levitt 

Your conditional expression to find the linked issues with a "Done" status is returning a list of comma-separated values.  If you stick that into a created variable, e.g. varDoneList, you could then count them:

{{varDoneList.split(",").size}}

To get the non-done count, just subtract that from your total count.

Kind regards,
Bill

Doug Levitt
Contributor
October 26, 2021

Hi @Bill Sheboy 

Thanks.  That is very helpful.

As I think about my ultimate solution, I have a more complex question...

Assume, I have the following links:

  • Blocker
    - inward: "is blocked by",
    - outward: "blocks",

According to the json structure, each link is associated with a:

  • Type which has a name {{issuelinks.type.name}} -- e.g. Blocker
  • Inward value {{issuelinks.type.name.inward}}  -- e.g. "is blocked by"
  • Outward value {{issuelinks.type.name.outward}} -- e.g. "blocks"

So, I am now interested in populating the following custom fields for each jira issue:

TicketsIamDependentOn

  • Contains the keys of all links of type "is blocked by" (which is an inward link)
  • I want to ignore inward links of other types and all outward links
  • Note: keys for inward links are stored in {{issuelinks.inwardIssue.key}}

TicketsThatDependentOnMe

  • Contains the keys of all links of type "blocks" (which is an outward link)
  • I want to ignore outward links of other types and all inward links
  • Note: keys for outward links are stored in {{issuelinks.outwardIssue.key}}

countOfAllDependentLinks

  • Contains the count of all links which are set to "is blocked by"
  • I want to ignore inward links of other types and all outward links

countOfOpenDependentLinks

  • Contains the count of all links which are set to "is blocked by" which are not Done
  • I want to ignore issue links of other types and all outward links
  • Note: Status is stored in {{issuelinks.outwardIssue.status.name}}

I suppose I don't want to simply count the entries in the issuelinks list.  Rather, I want to take action based upon other attributes in the json. I am unclear how to specify this. Any ideas or pointers on how to do this?

Thanks,

Doug

Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 26, 2021

Hi, Doug!

I believe what you ask is possible with list functions and the list filtering capability:

https://community.atlassian.com/t5/Automation-articles/Filtering-smart-value-lists/ba-p/1827588

With that, you probably can pull out the keys by type into a created variable, and then use that for your dependency list and count.  Removing any two-way duplicates (due to multiple linkages types) could be a bit tricky.

I recall previously doing something like this as an experiment with variables, lists, text, and regular expressions.  This new feature seems much better.

Kind regards,
Bill

Like Doug Levitt likes this
Doug Levitt
Contributor
October 26, 2021

Hi @Bill Sheboy 

Wow.  That new feature is cool.  I will definitely give it a try.

Like Bill Sheboy likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events