Automation Rule | Sum up linked issue count and update the same on the parent issue

Platform Notice: Cloud Only - This article only applies to Atlassian products on the cloud platform.

Summary

Scenario: Consider the below Jira issues:

  • Issue A (parent issue)

  • Issue B, Issue C (linked to A)

  • Issue D, Issue E, Issue F (linked to B or C)

Requirement: You wish to capture the total linked issues count on the parent issue (Example: Count of B, C, D, E, F issues and add it to Issue-A)

Flow: When the automation rule is triggered from Issue A, it should calculate the count of all the linked issues (up to 3 levels) and then sum up in log action.

Solution

Set up the automation rule :

Trigger: Manual trigger

Lookup issues:

  • JQL: issue in linkedIssues(key)

Create variable:

  • Variable name: count

  • Smart value: {{lookupIssues.size}}

Create variable:

  • Variable name: jql

  • Smart value:

    • ({{#lookupIssues}}issue in linkedIssues("{{key}}", "is caused by"){{^last}} OR {{/}}{{/}}) AND issue not in ({{#lookupIssues}}"{{key}}",{{/}}"{{triggerIssue.key}}")

Lookup issues:

  • JQL: {{jql}}

Create variable:

  • Variable name: totalCount

  • Smart value : {{#=}}{{count}} + {{lookupIssues.size}}{{/}}

Log action :

  • Log message: count: count --- total: totalCount

Explanation :

1st Lookup issue

  • Lookup 1: Lookup issues: issue in linkedIssues(key)

    • The JQL query in this look-up section would check all the linked Issues in the key in our example it is Issue ASo the result it would return is Issue B and Issue C

1st Create Variable

  • Create variable 1

    • Create variable :

    • Variable name: count

    • Smart value: {{lookupIssues.size}}

      • We have created a variable name "count" to keep a tab of the number of issues in the current issue, that we would need to call in future. In our example, it would be 2 as B and C have been added on A. When checking from B or C it would include , E, F that count size 3

2nd Create Variable

  • Create variable 2

    • Create variable :

    • Variable name: jql

    • Smart value :({{#lookupIssues}}issue in linkedIssues("{{key}}", "is caused by"){{^last}} OR {{/}}{{/}}) AND issue not in ({{#lookupIssues}}"{{key}}",{{/}}"{{triggerIssue.key}}")

      • Defining variables to fetch the linked issues on the Issue and exclude Parent issue-A further. We will use this variable further

Lookup Issues 2

  • LookUp issue 2 query

    • Lookup issues :

    • JQL: {{jql}}

      • This would return the Output of the above query would beOutput(issue in linkedIssues("Issue-A") OR issue in linkedIssues("Issue-B", "Issue-C")) AND issue not in ("Issue-A","Issue-B","Issue-C")

3rd Create Variable

  • Create variable 3

    • Create variable :

    • Variable name: totalCount

    • Smart value : {{#=}}{{count}} + {{lookupIssues.size}}{{/}}

      • In this variable, we are performing calculation by performing addition of {{count}} and {{lookupIssues.size}}.

      • It would be 2+ 3

      • Output : 2+ 3 = 5

Here is the automation rule JSON file to import:

1 {"cloud":true,"rules":[{"id":14535708,"clientKey":"fcb18f79-08d6-35bd-9c47-b1e204f45645","name":"Check Linked issue for all hierarchy","state":"DISABLED","description":"","authorAccountId":"6362284b01c2ff842c19db70","actor":{"type":"ACCOUNT_ID","value":"557058:f58131cb-b67d-43c7-b30d-6b58d40bd077"},"created":1693299652673,"updated":1693299652673,"trigger":{"id":"312978043","component":"TRIGGER","parentId":null,"conditionParentId":null,"schemaVersion":1,"type":"jira.manual.trigger.issue","value":{"inputFromUsers":false,"inputPrompts":[],"groups":[],"jQLFilter":null},"children":[],"conditions":[],"connectionId":null},"components":[{"id":"312978044","component":"ACTION","parentId":null,"conditionParentId":null,"schemaVersion":1,"type":"jira.lookup.issues","value":{"id":"_customsmartvalue_id_1692714309808","name":{"type":"FREE","value":"lookupIssues"},"type":"JQL","query":{"type":"SMART","value":"issue in linkedIssues({{key}})"},"lazy":false},"children":[],"conditions":[],"connectionId":null},{"id":"312978045","component":"ACTION","parentId":null,"conditionParentId":null,"schemaVersion":1,"type":"codebarrel.action.log","value":"{{lookupIssues}}","children":[],"conditions":[],"connectionId":null},{"id":"312978046","component":"ACTION","parentId":null,"conditionParentId":null,"schemaVersion":1,"type":"jira.create.variable","value":{"id":"_customsmartvalue_id_1692714637187","name":{"type":"FREE","value":"count"},"type":"SMART","query":{"type":"SMART","value":"{{lookupIssues.size}}"},"lazy":false},"children":[],"conditions":[],"connectionId":null},{"id":"312978047","component":"ACTION","parentId":null,"conditionParentId":null,"schemaVersion":1,"type":"jira.create.variable","value":{"id":"_customsmartvalue_id_1692717734917","name":{"type":"FREE","value":"jql"},"type":"SMART","query":{"type":"SMART","value":"({{#lookupIssues}}issue in linkedIssues(\"{{key}}\"){{^last}} OR {{/}}{{/}}) AND issue not in ({{#lookupIssues}}\"{{key}}\",{{/}}\"{{triggerIssue.key}}\")"},"lazy":false},"children":[],"conditions":[],"connectionId":null},{"id":"312978048","component":"ACTION","parentId":null,"conditionParentId":null,"schemaVersion":1,"type":"codebarrel.action.log","value":"{{jql}}","children":[],"conditions":[],"connectionId":null},{"id":"312978049","component":"ACTION","parentId":null,"conditionParentId":null,"schemaVersion":1,"type":"jira.lookup.issues","value":{"id":"_customsmartvalue_id_1692717357777","name":{"type":"FREE","value":"lookupIssues"},"type":"JQL","query":{"type":"SMART","value":"{{jql}}"},"lazy":false},"children":[],"conditions":[],"connectionId":null},{"id":"312978050","component":"ACTION","parentId":null,"conditionParentId":null,"schemaVersion":1,"type":"codebarrel.action.log","value":"{{lookupIssues}}","children":[],"conditions":[],"connectionId":null},{"id":"312978051","component":"ACTION","parentId":null,"conditionParentId":null,"schemaVersion":1,"type":"jira.create.variable","value":{"id":"_customsmartvalue_id_1692714668673","name":{"type":"FREE","value":"totalCount"},"type":"SMART","query":{"type":"SMART","value":"{{#=}}{{count}} + {{lookupIssues.size}}{{/}}"},"lazy":false},"children":[],"conditions":[],"connectionId":null},{"id":"312978052","component":"ACTION","parentId":null,"conditionParentId":null,"schemaVersion":1,"type":"codebarrel.action.log","value":"count: {{count}} --- total: {{totalCount}}","children":[],"conditions":[],"connectionId":null}],"canOtherRuleTrigger":false,"notifyOnError":"FIRSTERROR","projects":[],"labels":[],"tags":[{"id":41776027,"tagType":"IS_RULE_UPDATED","tagValue":"true"}],"ruleScope":{"resources":["ari:cloud:jira:7bbd0f61-9cf7-46a8-a02c-5d635b174db8:project/10015"]},"ruleHome":{"ruleLifeCycleHome":{"locationARI":"ari:cloud:jira:7bbd0f61-9cf7-46a8-a02c-5d635b174db8:project/10015"},"ruleBillingHome":{"locationARI":"ari:cloud:jira-software::site/7bbd0f61-9cf7-46a8-a02c-5d635b174db8"}},"writeAccessType":"UNRESTRICTED","collaborators":[],"billingType":"NORMAL"}]}

NOTE

Copy the above JSON code in a file and save it as .json. Import it in JIRA to import the above rule.

Updated on May 31, 2024

Still need help?

The Atlassian Community is here for you.