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

Sara December 6, 2017

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
Sara January 19, 2018

Hello All,

Do you have code example on this ? 

0 votes
RianS
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 6, 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.

Sara December 15, 2017

Hi Rian,

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

Sara January 19, 2018

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

RianS
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 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";

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events