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,557,507
Community Members
 
Community Events
184
Community Groups

Set comment required based on another custom field value

Hi,

I want the comment added during the transition to be required or not depending on the option selected. I wrote the validator, unfortunately it does not work and does not require the user to add a comment.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours


def commentField = getFieldById("comment")
def cfManager = ComponentAccessor.getCustomFieldManager();
def cf = cfManager.getCustomFieldObjectByName("Options");

switch(issue.getCustomFieldValue(cf) as String){
case "No": commentField.setRequired(true)
}

 

1 answer

0 votes
Aidan Derossett _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.
May 29, 2018

Hey there Tomasz!

First, are you using a transition screen coupled with the Behaviour? Behaviours aren't active on just the View Issue Screen, so to get something like this working you'll need to implement some sort of transition screen that has these fields on it.

Second, if you are already using a transition screen, is the custom field that you are trying to get the value of also available on the same screen or is it just available on the issue? If it's available on the same screen as the Comments field, then you can use the Behaviour methods to get the field and the field value:

//Example
def otherField = getFieldByName("Field Name")
def otherFieldValue = otherField.value
//etc...

Additionally, what type of custom field are you trying to get a value from? For example, is it a Text field, a Single Select field, a Multi-select field, etc...

This info will help me try this out myself and see if I can get something figured out for you :D

Thanks!

Aidan

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events