Jira Automation: How to copy custom field values to the trigger issue using the Parent Link field (without using branch blocks)

Still need help?

The Atlassian Community is here for you.

Ask the community

Summary

There are a few limitations to the Action blocks on Jira Automation for on-prem solutions when compared to the current options available on the Jira Cloud, such as Variables and LookUpIssues that allows us to move values inside the rule's scope or to create a list of issues from which we can perform actions outside the branch scope.

Click here for more details on the limitation...

Limitation for "Parents" relationship using custom fields:

Jira Automation Branching blocks allow us to use a few options to find the issues we need to copy values from or to, however, how we can move these values are limited to "Copy from..." there's no option to "Copy to...".

The options are also limited to a few "parenthood" options using a few default fields such as Epic Link and Epic Name (parent/child), and Task/Sub-Tasks.

However, if using a few custom fields or apps such as Advanced roadmaps, we can create new Hierarchies for issuetypes and Jira usually does that using the Parent Link custom field.

The Jira Automation Action and Branching blocks haven't added the parenting method option yet:

JSWSERVER-21254 - Getting issue details... STATUS

JIRAAUTOSERVER-79 - Getting issue details... STATUS

JIRAAUTOSERVER-135 - Getting issue details... STATUS



Known workaround: Branch block for JQL

Use custom fields such as the Parent Link in order to "branch" the parent issues by using the JQL on the Branch block:

Limitations of the workaround:

  • This rule can only copy values from the trigger issue to the branch issues.
  • If we triggered the rule on the target issue, we cannot use this method to retrieve values as there's no way to keep the values found on the branch outside the branch.
  • The Jira cloud feature "Variables" allow us to store this value in a "global" variable and use it outside the branch during the rule scope.
  • Any action inside the block will be performed at the same time in every issue that matches the JQL regardless of the "order" on the branch.

Solution: Send web request action block for Jira's REST API

Jira has a few inbuilt options to use the REST API inside the Automation rules.

If the rule was triggered by an issue (the example {{triggerissue}} is KAN-42) the next step is to have a source issue key to GET or PUT values into.

In this example, we'll use the "Parent Link" field, which has a parent issue key "KAN-35".

We'll need to authenticate a user that will be the REST actor. However, since Jira's REST API is well documented this can be done in several ways, and for this "proof-of-concept" example we'll not develop further on the authentication steps and the examples use the basic hashed password exactly as this guide:

1. Action: Send web request:

Use the Action block Send web request to run a GET on the issue we need to get values from:

<jira-URL>/rest/api/latest/issue/<ISSUE-KEY>?fields=<CF_ID>&fields=<CF_ID>...

(info) Notice that we can use smart values for several parametrisable values such as Jira's URL and Parent Link fields.

Optional: Verify the URL request, responses, and payloads:

Click here to expand...

(info) The validation tool will use the provided issue key as the "{{issue.key}}" smart value on the URL or ignore it if you don't need it.

(star) The Payload structure is:

fields > customfield_10110 > 127

(star) How to find the id for custom field(s)?

We can check all custom fields names and IDs using this REST API to generate a JSON with all the issue data:

<jira-URL>/rest/api/latest/issue/KAN-35?expand=names

(info) Use a JSON viewer tool or search for the custom field's name and the "customfield_xxxxx" ID associated with it at the end of the file.

2. Smart-Values to use the payload's contents:

Here's the trick! By using the smart value: 

{{webhookResponse.body.<key/value/etc>}}

Using dot notation we can retrieve the response structure mentioned from our GET:

{{webhookResponse.body.fields.customfield_10110.value}}

(lightbulb) I.e: fields > customfield_10110 > 127

(info) Different custom field types will have parameters, the tag containing the value we want might change to "key" or some other, check on the JSON to find the correct one for each case.

Example: Action: Edit issue

On the "Edit issue action" block we can set the values in any available field, as long as the field accepts the value format:


{{webhookResponse.body.fields.customfield_10110.value}}

(info) This smart value can also be used with the Conditions, Actions, and Branch blocks.

Find more details and other smart values for this feature on this page: webhookResponse

Last modified on Nov 17, 2022

Was this helpful?

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