Custom field mandatory based on another field on create issue screen

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

This widget could not be displayed.

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

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)

 

hi nidhi

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

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!!

 

This widget could not be displayed.

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?

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

491 views 3 18
Read article

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