Can Elements Connect fields be manipulated from a ScriptRunner Behaviours script?


Partially

Most features of ScripRunner Behaviours can be applied on an Elements Connect field with some exceptions.

The table below summarize what can be done, or not.



Feature
Comment
Making an Elements Connect field mandatory depending on other data entered on the issue screen

(tick)


Making a field mandatory depending on an Elements Connect field

(tick)

getFormValue() returns the key of the Elements Connect field in a JSON object:

import com.onresolve.jira.groovy.user.FormField;
import groovy.json.JsonSlurper

FormField descriptionField = getFieldById("description")
FormField elementsConnectField = getFieldById("customfield_10000")
String connectFieldValue= elementsConnectField.getFormValue()
if(connectFieldValue){
    def jsonSlurper = new JsonSlurper()
    def json = jsonSlurper.parseText(connectFieldValue)
    def connectFieldKeys = json["inputValues"]

    if (connectFieldKeys[0].equals("10525")) {
        descriptionField.setRequired(true)
    }
    else {
        descriptionField.setRequired(false)
    }
}
Make an Elements Connect field hidden depending on other data entered on the issue screen

(tick)

Make a field hidden depending on an Elements Connect field data

(tick)

getFormValue() returns the key of the Elements Connect field in a JSON object:

import com.onresolve.jira.groovy.user.FormField;
import groovy.json.JsonSlurper

FormField descriptionField = getFieldById("description")
FormField elementsConnectField = getFieldById("customfield_10000")
String connectFieldValue= elementsConnectField.getFormValue()
if(connectFieldValue){
    def jsonSlurper = new JsonSlurper()
    def json = jsonSlurper.parseText(connectFieldValue)
    def connectFieldKeys = json["inputValues"]

    if (connectFieldKeys[0].equals("10525")) {
        descriptionField.setHidden(true)
    }
    else {
        descriptionField.setHidden(false)
    }
}
Making an Elements Connect field read-only dependent on user role or group

(tick)


Doing server-side validation of Elements Connect field data, before the issue screen is submitted

(tick)

getFormValue() returns the key of the Elements Connect field:

import com.onresolve.jira.groovy.user.FormField;
import groovy.json.JsonSlurper

FormField elementsConnectField = getFieldById("customfield_10000")
String connectFieldValue= elementsConnectField.getFormValue()
if(connectFieldValue){
    def jsonSlurper = new JsonSlurper()
    def json = jsonSlurper.parseText(connectFieldValue)
    def connectFieldKeys = json["inputValues"]

    if (connectFieldKeys[0].equals("10525")) {
        elementsConnectField.setError("This is not a valid value");
    } else {
        elementsConnectField.setError("")
    }
}
Setting the value of an Elements Connect field

(warning)

(partially)

setFormValue can be used to set the value of Live Text and Snapshot Text Elements Connect fields for all editor types except read-only.
Live User, Snapshot Date time and Snapshot Date fields cannot be set via Behaviour scripts.

The value format depends on the type of the Elements Connect field:

  • for Snapshot Text fields, the format is simply the value as seen in the issue
  • for Live Text fields, the format is a JSON object built thus: {inputValues: ["key1", "key2", ...]} where key1, key2 are the elements defined as keys in your query configuration.

Set the value of a Snapshot text field:

import com.onresolve.jira.groovy.user.FormField;

FormField jiraField = getFieldById(getFieldChanged())
FormField elementsConnectField = getFieldById("customfield_10000")

if (jiraField.getFormValue() == "test") {
	elementsConnectField.setFormValue("Field value");
}

Set the value of a Live Text field:

import com.onresolve.jira.groovy.user.FormField;

FormField jiraField = getFieldById(getFieldChanged())
FormField elementsConnectField = getFieldById("customfield_10001")

if (jiraField.getFormValue() == "test") {
	elementsConnectField.setFormValue("{\"inputValues\": [\"10000\", \"10001\"]}");
}

A known issue prevents setting values when they are outside the currently available options in the field at the time of the script execution.

This bug has been resolved in the version 6.10.2

Setting a field value dependent on an Elements Connect field

(tick)

getFormValue() returns the key of the Elements Connect field in a JSON object:

import com.onresolve.jira.groovy.user.FormField;
import groovy.json.JsonSlurper

FormField descriptionField = getFieldById("description")
FormField elementsConnectField = getFieldById("customfield_10000")
String connectFieldValue= elementsConnectField.getFormValue()
if(connectFieldValue){
    def jsonSlurper = new JsonSlurper()
    def json = jsonSlurper.parseText(connectFieldValue)
    def connectFieldKeys = json["inputValues"]

    if (connectFieldKeys[0].equals("10525")) {
        descriptionField.setFormValue("this is it");
    }
    else {
        descriptionField.setFormValue("this is something else");
    }
}