Edit issue fields with data from Lookup Issues automation action in Jira
Platform Notice: Data Center and Cloud By Request - This article was written for the Atlassian Data Center platform but may also be useful for Atlassian Cloud customers. If completing instructions in this article would help you, please contact Atlassian Support and mention it.
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 Lookup Issues action was introduced to Automation for Jira Data Center in version 9.0.1, allowing users to query for issue properties and then use them in further actions. However, as stated in our documentation for the lookupIssues smart value, it only supports a limited range of properties and doesn't support retrieving arbitrary custom field values.
We currently have a suggestion to add this capability, but it hasn't been implemented yet: JIRAAUTOSERVER-877 - Lookup issue action - Add support for more fields
Environment
Automation for Jira Data Center 9.0.1 or later (bundled with Jira Data Center 9.11 or later)
Solution
In situations where we need to look up a single issue and retrieve a single custom field value, we can work around the limitations of the Lookup Issues action by using the Create Variable action, which was also introduced in Automation for Jira 9.0.1.
As a practical example, let's take the following scenario - we would like to implement a manual automation trigger for Epic issues that will search for all the issues under an Epic and do the following:
Set the Epic issue's Target start date to the earliest Target start date among the issues linked to the Epic
Set the Epic issue's Target end date to the latest Target end date among the issues linked to the Epic
We can do this by constructing an automation rule. As a reminder, it's generally best to declare any variables outside of a branch when we intend to retrieve values stored in those variables later.
Let's build the automation rule in parts.
Part 1: Initialize variables
Here, we're simply creating the rule and setting up our variables with null values. We'll add real values based on our Lookup Issues action later.
Visit your project > Project settings > Automation for a project-scoped rule, or Global automation for a globally-scoped rule
Create a new rule
Trigger: Manual
Issue fields condition: Issue type = Epic
Action - Create variable:
Variable name: TargetStart
Variable value: null
Action - Create variable:
Variable name: TargetEnd
Variable value: null
Part 2: Set variable values based on issue data
Next, we use Lookup issues to return a single issue key and use that issue key in a For JQL branch. We extract the custom field value from the branch using Create variable.
Action - Lookup issues:
JQL:
"Epic Link" = {{issue.key}} AND "Target start" IS NOT EMPTY ORDER BY "Target start" ASC
For each branch on related issues
JQL:
key = {{lookupIssues.key.first}}Action - Create variable:
Variable name: TargetStart
Variable value:
{{issue.Target Start}}
Action - Lookup issues:
JQL:
"Epic Link" = {{issue.key}} AND "Target end" IS NOT EMPTY ORDER BY "Target end" DESC
For each branch on related issues
JQL:
key = {{lookupIssues.key.first}}Action - Create variable:
Variable name: TargetEnd
Variable value:
{{issue.Target End}}
Part 3: Edit Epic with variable values
Finally, we use the variables to set the original trigger issue's fields as desired.
Action - Edit issue
Don't choose any fields to set, and expand the Advanced section
Add the following code:
{ "fields": { "Target start": "{{TargetStart}}", "Target end": "{{TargetEnd}}" } }
Was this helpful?