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 except one.

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_10605")
String connectFieldValue= elementsConnectField.getFormValue()
def jsonSlurper = new JsonSlurper()
if(connectFieldValue)
    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_10605")
String connectFieldValue= elementsConnectField.getFormValue()
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_10605")
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("")
    }
}
Set the value of an Elements Connect field from a Behaviour's script

(error)

CO-3116 - Getting issue details... STATUS
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_10605")
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");
    }
}