The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

For loop - Behaviour

Joel Batac
Contributor
August 14, 2023

HI,

 Is it possible to use a for loop for behaviour. Basically, I have a select field (Number of Fields - options 1-10) and 10 text fields (Field Name 1 .. Field Name 2). Based on the selection in Number of Fields, I need to show the exact number of test field. Example, if I select 1 (on Number of Fields), Field Name 1 should show up. Same thing if I select 10, Field Name 1 to Field Name 10 should show up.

So I'm wondering if I can use for loop to accomplish this?

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

1 vote
PD Sheehan
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 Champions.
August 15, 2023

With Groovy there are much better solutions for looping than standard for loops.

 

Try this:

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

@BaseScript FieldBehaviours fieldBehaviours

def selectFld = getFieldByName('Number of Fields')
def numberOfFieldsToShow = 0
def numberOfFieldsTotal = 10
if(selectFld.value) {
numberOfFieldsToShow = selectFld.value as Integer
}
1.upto(numberOfFieldsTotal){number->
def visible = number <= numberOfFieldsToShow
getFieldByName("Field Name $number").setHidden(!visible)
}

 (the first 3 lines are only needed if you work with an external IDE like intellij)

Joel Batac
Contributor
August 16, 2023

Thanks Peter! I'll try this one. 

TAGS
AUG Leaders

Atlassian Community Events