How can I set a default Value via Script Runner when a custom field gets a specific value ?


I have a custom field "Client" and another one "relevant entities".

When the field "Client" gets a specific value, let's say XX; I'd need that the "relevant entities" field to set a default value, YY.

I tried this code viaScript Runner-Behaviour plugin;

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

FormField fieldClient = getFieldById("customfield_10112") def RelevantEntities = getFieldById("customfield_10367") def defaultValue = ("[10643]")

String client = fieldClient.getValue()

if (client.getvalue("[10297]") { //XX    RelevantEntities.setFormValue(defaultValue) }

but it does not work. Any ideas please?

Thanks in advance for your help


2 answers

1 accepted

Hi Mel,

Assuming your Client and relevant entities fields are of the Select List type then you could use code similar to the example below in order to achieve your requirements above. The example below was created using JIRA 6.4 and Script Runner version

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

// Get the custom fields by Name
def fieldClient = getFieldByName("Client") 
def RelevantEntities = getFieldByName("relevant entities") 

// Get the value of the client field to test
def clientVal = fieldClient.getValue()

//The ID of the YY option on the relevant entities select list field
int defaultVal = 10203

// If the value selected is XX then set the default value in the relevant entities select list 
if (clientVal =="XX") {


I hope this helps



Hi Mel, I am glad the solution works. Thank you for accepting the answer. Kristian

Hi Melissa, What types your custom fields have ?

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Posted 10 hours ago in Jira

We want to know what Jira Service Desk apps you're using!

Hi Community! My name is Amir and I’m on the Jira Service Desk product marketing team at Atlassian. Our team would love to understand how you’re leveraging our ecosystem for Jira Service Desk. Wha...

33 views 0 5
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you