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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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
Community showcase
Asked in Jira Service Desk

Calling all Insight users, we need your help!

Hello Insight users,  As part of our (Mindville's) acquisition by Atlassian, our training team is looking to build some new Insight training materials. It would really helpful if you can ...

162 views 1 1
View question

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you