Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,558,952
Community Members
 
Community Events
184
Community Groups

How to make a field mandatory based on value in the another field

Anirudh Pratap Verma
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
Apr 05, 2023

Hi All,

 

I am trying to make a field mandatory based on value in the another field using below code in script runner. But it is not working 100% correctly -

- When i create a JIRA ticket and make the select 1 in the field "Quality Assessment", it doesnt show "Quality Comment" field as mandatory. We have to click on update and again edit the JIRA ticket to see the field "Quality Comment" as mandatory. 

- Also it doesnt stop state transition even when the field is made mandatory and not filled. 

 

The only thing it does is that it doesnt allow to edit the JIRA till the time we fill the mandatory field field "Quality Comment".

 

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

@BaseScript FieldBehaviours behaviours

def sourcefield = getFieldByName('Quality Assessment')
def RCAfield = getFieldByName('Quality Comment')

String sourceValue = sourcefield.getValue()

if(sourceValue.startsWith("1")){
RCAfield.setRequired(true);
} else {
RCAfield.setRequired(false);
}
How can I resolve our two problems mentioned above. Even if we are able to solve the second problem of transitioning then also i am okay.
Thanks, 

 

1 answer

0 votes
Benjamin
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Apr 05, 2023

Hi @Anirudh Pratap Verma ,

 

Based on your script, the values will only take place after an edit which is the expected behavior you have. You'll need to have a line above to check for when field are change on the screen to check against the value. Here's the example line:

def sourcefield = getFieldById(getFieldChanged())

 

Would not recommend using start with 1. If you know the value is 1, would state it with an = statement.

 

-Ben

Anirudh Pratap Verma
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
Apr 06, 2023

Thanks Ben for your response!!

I put the below code in the server side script for a the custom field which is responsible for  change in the below "Quality Comment" and it worked.

 

For only below two options field should display and show as mandatory. 

 

def QACommentfield = getFieldByName("Quality Comment")
def failReasonfield = getFieldById(getFieldChanged())

def selectedoption1 = failReasonfield.getValue() as String
def selectedoption2 = failReasonfield.getValue() as String
def isOptionSelected1 = selectedoption1 == "1 - Alarming"
def isOptionSelected2 = selectedoption2 == "2 - Warning"

QACommentfield.setHidden(! isOptionSelected1 && ! isOptionSelected2)
QACommentfield.setRequired(isOptionSelected1 || isOptionSelected2)

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
9.4.0
TAGS
AUG Leaders

Atlassian Community Events