Skip to main content
Skip table of contents

Behaviours - Fields update

In this example, we update the Environment(s) to book field with the list of Environments corresponding to the Category selected in a single-select custom field.

image-20240927-085032.png

The Category field is a single-select custom field containing a hard-coded list of existing Golive environment category names. With a behavior triggered on this field, we read the value of the field, search for corresponding environments using the Golive Java API, and set the IDs as the value of the Environment(s) to book custom field.

image-20240927-085246.png

ScriptRunner Behaviour Field setup

GROOVY
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.apwide.env.api.GoliveAccessor
import com.apwide.env.api.Environments.SearchCriteria
import com.apwide.env.api.Environment
import java.util.List

@WithPlugin("com.holydev.env.plugin.jira-holydev-env-plugin")
@PluginModule
GoliveAccessor goliveAccessor

// Get selected category from "Category" single select custom field
String selectedCategory = getFieldByName("Category")?.getValue()

// Search environments related to the selected category name
List<Environment> envs = goliveAccessor.golive().environments.find(SearchCriteria.builder().categoryNames([selectedCategory]).build())

// Extract and convert to string environment ids
def envIds = envs.collect { env -> "${env.getId()}" }

// Update the Environment(s) to book custom field with the list of environment ids
getFieldByName("Environment(s) to book").setFormValue(envIds)
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.