Automation For Jira - Writing a rule that copies a field from a Parent to a Child issue as soon as the Child issue is linked to it

Still need help?

The Atlassian Community is here for you.

Ask the community

robotsnoindex

Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.

Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

 

Summary

The purpose of this article is to show how to configure a rule meant to copy the content of a field from a parent issue to a child issue, in the case the parent/child relationship is based on the hierarchy level configuration which is a feature from Advanced Roadmap, and which is dictated by the Parent Link field.

It is important to note that the Parent/Child relationship is different from the Parent/Sub-Task relationship which is documented in configuring sub-tasks. The Copy from parent action in rule Branches can only be used in automations to copy a field from a parent to a sub-task issue. However, it cannot be used to copy the value of a field from a parent to a child issue. This is the reason why implementing such use case can be a bit tricky, which is why this KB article was written.

(info) Note that the use case covered by this KB article is slightly different than the one covered in the other article Automation For Jira - Writing a rule that copies a field from a Parent to a Child issue when this field is updated. In this article, we will show how to copy the content of a field from a parent issue to a child issue, in the case where a child issue is added to a parent issue via the Parent Link field.

Environment

  • Jira Server/Data Center on any version from 8.0.0 (Or Jira Service Management from 4.0.0)
  • Automation For Jira on any version from 7.4.0

Solution

Since there is not action Copy from... available in rule branches that allows to copy the value from a Parent issue to a Child issue, one way to achieve this goal is to configure 2 separate automation rules which are detailed below.

For this solution, we will use the following example:

  • The hierarchy levels are configured so that the Initiative issue type is a parent of the Epic issue type:
  • With such hierarchy level configuration, we will have the Parent/Child relationship described in the examples below:
    • The issue SCRUM-55 is a parent issue of the issue SCRUM-25 (as shown in the Child Issues panel):
    • The issue SCRUM-25 is a child issue of the issue SCRUM-55 (as configured via the Parent Link issue):


Preliminary steps

Before configuring the 2 automation rules, you need to first identify the ID of the Parent Link custom field, since this ID will be different depending on your Jira installation:

  • Login as a Jira system admin user
  • Go to ⚙ > Issues > Custom Fields
  • Search for the Parent Link custom field, and click on ... > View

  • Get the ID from the URL: it is the custom field ID that is needed to configure the automation rule:

Rule configuration 1

The purpose of this rule is to add a new comment to the Parent issue (Initiative type issue) as soon as an Epic issue (child issue) is linked to it via the Parent Link field.

The automation rule will be configured like this:

  • Add the Field Value Change trigger
    • Fields to monitor for changes: Type the string "Parent Link" and press enter. The field will be populated with Parent Link (Match)
  • Add an Issue fields condition with the following settings:
    • Field: Issue type
    • Condition: Equal
    • Value: Epic
  • Add an Advanced compare condition with the following settings:
    • First Value: copy the text below, after replacing XXXXX with the ID of the Parent Link custom field

      {{triggerIssue.customfield_XXXXX}}
    • Condition: does not equal
    • Second value: leave it empty

  • Add a Branch rule component  with the following settings:
    • (warning) Un-tick the option Only include issues that have changed since the last time this rule executed 
    • Type of related issues: JQL
    • JQL: (info) There are 2 possible JQL queries that you can use, which both lead to the same result:

      • Option 1: enter the JQL query below, after replacing XXXXX with the ID of the Parent Link custom field

        key = {{triggerIssue.customfield_XXXXX}}
      • Option 2: use the JQL query below

        key in parentIssuesOf("{{triggerIssue.key}}")
  • Inside the Branch rule component, add the Comment on issue action with the following settings:
    • (warning) Un-tick the option Prevent duplicates by only adding this comment once to a particular issue. 
    • Comment:

      A new Epic issue was added to this parent issue.

The rule will look like this (make sure to change 10408 with the actual ID of the Parent Link custom field):

Rule configuration 2

The purpose of this rule is to copy the content of a field (for example, the "Labels" field) from a Parent issue (of type Initiative) to all the Child issues (issues of type Epic), as soon as the comment "A new Epic issue was added to this parent issue." is added to this issue.

 For this 2nd rule, make sure to tick the option Allow rule trigger in the Rule Details page, in order to allow the 1st rule to trigger this 2nd rule. Otherwise, this 2nd rue will not be triggered as expected:


The automation rule will be configured like this:

  • Add the Issue Commented trigger
  • Add an Issue fields condition with the following settings:
    • Field: Issue type
    • Condition: Equal
    • Value: Initiative
  • Add an Advanced compare condition with the following settings:
    • First Value: copy the text below:

      {{issue.comments.last}}
    • Condition: equals
    • Second value: copy the text below:

      A new Epic issue was added to this parent issue.
  • Add a Branch rule component with the following settings:
    • (warning) Un-tick the option Only include issues that have changed since the last time this rule executed 
    • Type of related issues: JQL
    • JQL: enter the JQL query below:

      "Parent Link" = {{triggerIssue.Key}}
  • Inside the Branch Rule component, add the Edit Issue action with the following settings
    • Choose the field of your choice (for example, "Labels") as the field to update, and select Copy from Trigger Issue


The rule will look like this (make sure to change Labels with the actual field you are trying to copy from the Parent to the Child issue):



Last modified on Jul 2, 2024

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.