Using or , it is easy to update Environment Custom Fields using other any issue information.

In this example, we have created 2 standard multi-select Jira fields:

  • “Applications”: to select the list of applications we want to book

  • “Categories”: to select the list of environment categories we want to book

Based on selected applications and categories, we want to automatically set the “Environments” custom field with the list of all matching environments to book.

Here is a script example you can adapt and re-use for that purpose:

def applicationsFieldKey = "customfield_12383"
def categoriesFieldKey = "customfield_12384"
def environmentsFieldKey = "customfield_12300"
def environmentsFieldAppKey = "apwide-environment-environments" // how to get this key:

def issueKey = issue.key"IssueKey: $issueKey")

def projectId ="ProjectId = ${projectId}")

def currentUser = user"Current user: $currentUser")

def selectedApplicationNames = issue.fields[applicationsFieldKey]*.value"Selected application names: ${selectedApplicationNames}")

def selectedCategoryNames = issue.fields[categoriesFieldKey]*.value"Selected category names: ${selectedApplicationNames}")

def environmentOptionValues = get("/rest/api/3/field/com.holydev.env.plugin.jira-holydev-env-plugin__${environmentsFieldAppKey}/option/suggestions/edit?projectId=${projectId}")
        .asObject(Map).body.values"Environments customfield option values: ${environmentOptionValues}")

def matchingEnvironmentOptions = environmentOptionValues.findAll {
    optionValue -> selectedApplicationNames?.contains( && selectedCategoryNames?.contains(
}"Matching environment options: ${matchingEnvironmentOptions}")

def matchingEnvironmentOptionIds = matchingEnvironmentOptions*.id"Matching environment option ids: ${matchingEnvironmentOptionIds}")

def issueUpdateBody = [
    fields: [
         "${environmentsFieldKey}"   : matchingEnvironmentOptionIds
]"Issue update body: ${issueUpdateBody}")

def updatedIssueResult = put("/rest/api/3/issue/${issueKey}")
        .header('Content-Type', 'application/json')
        .asString()"Updated issue result: ${updatedIssueResult}")