Automation - Update Epic custom field if same custom field of child issues have a particular value
Asked by Peter Brown:

I have a custom field 'RAG' that contains 3 possible values - Red, Amber \& Green

If 'RAG' value is changed on any child issue I would like to have the following checks automated and the value of the Epic 'RAG' field updated as per the rules below:

If any child issue has a value of RED the Epic should be RED

ELSEIF no child is RED but a child issue has a value of AMBER the Epic should be AMBER

ELSE if all child issues are GREEN the Epic should be GREEN


Answers:
author: Trudy Claspill
body: Hello [@Peter Brown](/t5/user/viewprofilepage/user-id/5319491)

Welcome to the Atlassian community.

You can do that with a rule like this:

(1) Triggered based on a change to the RAG field, first confirm that change occurred on an issue that is a child of an Epic.

(2) Then lookup up how many child issues of that Epic have RAG set to red, and record that number

(3) Then lookup up how many child issues of that Epic have RAG set to amber, and record that number

(4) Set up an IF/ELSE Condition

- check if the counter you had for child issues set to Red is more than 0. if it is, set RAG on the epic to red

- if the Red counter was not greater than 0, then check if the Amber counter is greater than 0. If it is, set RAG on the epic to Amber.

- If neither the Red not Amber counters was greater than 0, set RAG on the epic to green.

```
(1) TRIGGER: Field Value Changed
  Field: RAG
CONDITION: Related Issues
  Related Issues: Epic
  Condition: Exists

(2)ACTION: Lookup Issues
  JQL: "Epic Link" = {{issue.epic.key}} and "RAG"="Red"
ACTION: Create Variable
  Variable name: Red
  Smart Value: {{lookupIssues.size|0}}

(3)ACTION: Lookup Issues
  JQL: "Epic Link" = {{issue.epic.key}} and "RAG"="Amber"
ACTION: Create Variable
  Variable name: Amber
  Smart Value: {{lookupIssues.size|0}}

(4)CONDITION: IF/ELSE: 
  Advanced Compare
    First value: {{Red}}
    Condition: greater than
    Second value: 0

    FOR EACH: Related Issue
      Type of related issue: Epic (parent)

      ACTION: Edit issue
        set RAG field to Red

CONDITION: ELSE IF: 
  Advanced Compare
    First value: {{Amber}}
    Condition: greater than
    Second value: 0

    FOR EACH: Related Issue
      Type of related issue: Epic (parent)

    ACTION: Edit issue
      set RAG field to Amber

CONDITION: ELSE
    FOR EACH: Related Issue
      Type of related issue: Epic (parent)

      ACTION: Edit issue
        set RAG field to Green

```

comments: author: Peter Brown
body: Hi [@Trudy Claspill](/t5/user/viewprofilepage/user-id/3569011)

thank you for responding and providing a solution :)

I'm having a problem when I try to add the JQL you have posted in this part of your solution:

```
CONDITION: ELSE
    FOR EACH: Related Issue
      Type of related issue: Epic (parent)
```

When I choose the "Add component" I only get a "IF: Add a condition" option - there is no "ELSE" option?

Also - if the first check on the "Red" variable finds a child with RAG=Red .. does the automation stop after setting the Epic to Red or does it continue on checking for Amber also?

I know your solution has "ELSE IF" for the Amber condition but both Red and Amber conditions simply have a IF condition only when I set the rule up?

Also .. also .. There will be children of the same epic who could have RAG=Red or Rag=Amber so it needs to exit after it finds the first child with Red .. is this built into automation rules?

thx

Pete


author: Trudy Claspill
body: Please provide screen images that show the rule you have created. I don't think you have created it according to my instructions.


Tags: cloud

jira-work-management-cloud