Custom field mandatory based on another field on create issue screen

nidhis July 8, 2016

Hi,

 

I wish to make a field on JIRA create screen mandatory based on the selection of another select list field.

 

I have tried below two solutions:

 

def childField = getFieldByName("US Market Access")

def parentField = getFieldById(getFieldChanged())

def selectedOption = parentField.getValue() as String

 

if ((selectedOption == "Yes") || (selectedOption == "No"))

{

  childField.setRequired(true)

}

else

{

  childField.setRequired(false)

 }

 

 

 

 

OR

 

FormField priField = getFieldById("16020")

FormField priJustField = getFieldById("15820")

String Criticality = (String) priField.getFormValue()

if (Criticality == "18170") { // 11306 is Blocker

priJustField.setRequired(false)

}

else{

priJustField.setRequired(true)

}

 

 

But both of them are making field mandatory, even if i dont select value of parent field.

 

i TRIED  "script runner" validator on create transition also "Has custom field value equal to " 

that also made the same issue.

 

Can you please suggest the script to use?

 

refrence help:

 

https://answers.atlassian.com/questions/267139/can-we-set-a-custom-field-as-mandatory-based-on-other-custom-field-value

 

Nidhi

2 answers

1 vote
Thanos Batagiannis _Adaptavist_
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.
July 8, 2016

Hi Nidhi,

If you want a behaviour try the following

def selectCFValue = getFieldByName("Single Select List CF").getValue()
def targetField = getFieldByName("US Market Access")

if (selectCFValue == "OptionA" || selectCFValue == "OptionB")
    targetField.setRequired(true)
else
    targetField.setRequired(false)

regards

Thanos

nidhis July 10, 2016

Hi, 

 

Thanks for that,

 

When I try it in the create transition of the workflow, its showing Field mandatory error even if I do not select any value in source instance:

def selectCFValue = getFieldByName("Impact Transaction Reporting").getValue()

def targetField = getFieldByName("US Market Access")

if (selectCFValue == "Yes" || selectCFValue == "No")

    targetField.setRequired(true)

else

    targetField.setRequired(false)

 

Thanos Batagiannis _Adaptavist_
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.
July 20, 2016

hi nidhi

I am a bit confused. Do you want a validator or a behaviour (the example above is a behaviour) ?  

roniz March 20, 2017

hi -Thanos Batagiannis I also have a question regarding this issue-

field A is a select list- single choice.

I want to create a configuration on the "create" screen-

if field A='x' --> I want to make field B mandatory.

 

Can you help me please?

Thanks!!

 

Like fobrutsky likes this
0 votes
Nadica Gaber March 6, 2018

Hi All,

 

The behavior script posted above:

 

def selectCFValue = getFieldByName("Single Select List CF").getValue()
def targetField = getFieldByName("US Market Access")

if (selectCFValue == "OptionA" || selectCFValue == "OptionB")
    targetField.setRequired(true)
else
    targetField.setRequired(false)

 

It works witch select lists. However if the source field is Tempo account filed it does not recognize neither the value or the ID of the account. Do you know the correct method to get the value for Tempo account Field?

Dan27 October 3, 2018

Hi @Nadica Gaber ,

I used your code on behaviour to the same issue.

I would like to make 'environment platform' field (Text Field type) a mandatory field, only if 'Patch type' field (Select List (single choice) type) = 'X'.

 

There is something I should choose or select in the behaviour settings? cause it didn't work for me..

This is my code:

def selectCFValue = getFieldByName("Patch Type")
def targetField = getFieldByName("Environment/ Platform")

if (selectCFValue.getValue() == "GA Point Patch" || selectCFValue.getValue() == "GA Cumulative Patch")
targetField.setRequired(true)
else
targetField.setRequired(false)

 

and attached the behaviour screen:

behaviour.JPG

Nadica Gaber October 4, 2018

Hi @Dan27,

You are missing getting of the value from Patch Type field.

Add  getValue():

def selectCFValue = getFieldByName("Patch Type").getValue()

Regards,

 

Nadica

 

Dan27 October 4, 2018

Hi @Nadica Gaber ,

Still not working...

my new code:

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours

def regressionIssueField = getFieldById(getFieldChanged())
def targetField = getFieldByName("Environment/ Platform")

def selectCFValue = getFieldByName("Patch Type").getValue();

if (selectCFValue == "GA Point Patch" || selectCFValue == "GA Cumulative Patch") {
targetField.setRequired(true)
} else {
targetField.setRequired(false)
}

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events