Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

×
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

How to add behaviour

Hello,

 

I'm trying to add a behaviour that should make the field "Impediment reason" mandatory, when "Flagged" is selected.

 

I'm trying with this:

 

import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Logger
import org.apache.log4j.Level


FormField flaggedField = getFieldByName("Flagged")
FormField reasonField = getFieldByName("Impediment Reason")

def flagged = flaggedField.getValue()

if(flagged.toString() == '1')
    reasonField.setRequired(true)
else
    reasonField.setRequired(false)

 

But nothing seems to happen. I don't get any errors, so I'm not even sure if I added it correctly. I went to behaviours, select "add new", then I clicked on fields, and added an initialiser, where I put the above code. Then I mapped it to all projects and all issue types.

 

Please let me know what I'm doing wrong.

 

Thank you.

2 answers

Suggest an answer

Log in or Sign up to answer
0 votes
Joshua Yamdogo @ 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.
Aug 28, 2017

Arama,

Your code above looks almost correct, but it should not be in an initiailizer. Initializers are generally used for setting default values for fields, not for monitoring the value of a field. Put this code in a server-side script attached to the "Flagged" field.

import com.onresolve.jira.groovy.user.FormField

FormField flaggedField = getFieldByName("Flagged")
FormField reasonField = getFieldByName("Impediment Reason")

def flagged = flaggedField.getValue()

if(flagged.toString() == '1') {
reasonField.setRequired(true)
}
else {
reasonField.setRequired(false)
}

Hello Joshua,

 

Thank you very much for your reply.


I tried that and it still seems to not work.

Screenshot added:

behaviour2.jpgbehaviours3.jpg

Joshua Yamdogo @ 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.
Aug 31, 2017

Hi Arama,

Are you using this behaviour with a JIRA Service Desk project? Or is this being used on JIRA server?

Also, what type of field is "Flagged"? Is it a text field, checkbox field, select list, etc...?

Hello,

We are on a JIRA server, and Flagged is a checkbox.

It's working now.

 

def flagged = getFieldById(getFieldChanged())
def impediment = getFieldByName("Impediment Reason")

if(flagged.getValue() != null){
    impediment.setRequired(true)
}
else { impediment.setRequired(false) }
0 votes
Lars Olav Velle
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.
Aug 28, 2017 • edited

I`m thinking you are more likely to get a good answer at the developer community:

https://community.developer.atlassian.com

 

-Lars

Thank you Lars, I also added the question there.

TAGS
AUG Leaders

Atlassian Community Events