How to set custom field value based on another custom field value in JIRA

Hi Team,

Could you please help on this script. I am very new to grrovy script 

How Can we set the capitalization field automatically based on the value of BugType field, meaning if the BugType is Production set Capitalization to No and if the BugType is Pre-Production set Capitalization to Yes.

2 answers

0 votes
Rian Spivak Community Champion Dec 06, 2017

My thought on doing this would be to create a script runner Script Custom Field. This would make the field read-only but can be searchable, and the value would be dependent on a script. That way you can have the script check the value of the BugType type field and present the "Yes" or "No" values automatically and change whenever the BugType field changes.

Hi Rian,

  Do you have code example on this ? I am new to groovy script.

Hi @Rian Spivak, Do you have any code example on this ?

Rian Spivak Community Champion Jan 20, 2018

Sure. Here's a sample. The return sets the value of the scripted field. It looks up the custom field based on name. There is another function which may be safer which looks up the function based on Id, called getCustomFieldObject(). I used the function which looks up by name to make the code easier to follow but could return a collection of customfield objects based on the API.

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def myTestField = customFieldManager.getCustomFieldObjectsByName('BugType');
//def myTestField = customFieldManager.getCustomFieldObject(10024);

def testvalue = issue.getCustomFieldValue(myTestField);

if (testvalue.toLowerCase() == 'production') return "No";
else return "Yes";

Hello All,

Do you have code example on this ? 

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Oct 11, 2018 in Marketplace Apps

You + one app + a desert island...

Hi all! My name is Miles and I work on the Marketplace team. We’re looking for better ways to recommend and suggest apps that are truly crowd favorites, so of course we wanted to poll the Community. ...

2,604 views 5 6
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