Skip to main content
Skip table of contents

Set environment custom field based on other fields

Using a https://docs.adaptavist.com/sr4js/latest/features/listeners , it is easy to update Environment Custom Fields .

In this example, we automatically select the target Environment in our Change Requests (Jira issues), depending on the type of change defined in the "Promotion Path" field (Production Fix, Change Request, Enhancement).

For that, we have created a ScriptRunner Listener:

ScriptRunner Listener

GROOVY
import com.apwide.env.api.Golive
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.apwide.env.api.GoliveAccessor
import com.atlassian.jira.component.ComponentAccessor

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

final environmentCustomFieldName = 'Environment(s)'
final triggerCustomFieldName = 'Promotion Path'

final customFieldManager = ComponentAccessor.customFieldManager
final issue = event.issue

def triggerCustomField = customFieldManager.getCustomFieldObjects(issue).findByName(triggerCustomFieldName)
assert triggerCustomField : "Could not find custom field with name $triggerCustomFieldName"

if (issue.getCustomFieldValue(triggerCustomField).toString() == "Enhancement") {
  def environmentField = golive.environmentFields.getByName(issue, environmentCustomFieldName)
  assert environmentField : "Could not find custom field with name $environmentCustomFieldName"
  environmentField.setValueByName("eCommerce DEV1", "eCommerce Test")
}

JavaScript errors detected

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

If this problem persists, please contact our support.