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

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


1 badge earned


Participate in fun challenges

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


Gift kudos to your peers

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


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!


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
Community Members
Community Events
Community Groups

For loops in Behaviors?

We are adding a for loop in a Behavior to collect the option IDs of a multi-select field. 

On Script Console, the for loop works -- it gathers the option IDs and puts it in a list. 

However, when added to a Behavior, the for loop breaks the entire behavior. Dx


Has anyone had success with a for loop on Behaviors? For reference here is our behavior: 


import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.jql.parser.JqlQueryParser
import static org.apache.commons.collections.CollectionUtils.*
final productLine = "Product Line(s)"
if (getBehaviourContextId() == "create-epic-button") {
// Get some components
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def issueManager = ComponentAccessor.issueManager
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def optManager = ComponentAccessor.getOptionsManager()
//Parent Link
def parentLink = getFieldByName("Parent Link")
def parentLinkValue = parentLink.getValue()
def contextIssue = issueManager.getIssueObject(getContextIssueId())
//Product Line
def productLineName = ComponentAccessor.customFieldManager.customFieldObjects.findByName(productLine) //Get Objects
def productLineList = getFieldByName(productLine).getValue() as List //Get Values as List
log.warn("Product Line List: $productLineList")
//Get Product Line Field Config
def productLineConfig = productLineName.getRelevantConfig(contextIssue)
log.warn("Product Line Field Configuration: $productLineConfig")
//Get Product Line Field Value Options
def productLineOptions = optManager.getOptions(productLineConfig)
log.warn("Product Line Options: $productLineOptions")
def targetValues = []
for (i in productLineList) {
log.warn "processing $contextIssue value = $i"
//Convert i to a string and define it in a variable
def newVal = i.toString()
//Get Product Line Option ID
def productLineOptionID = productLineOptions. find { it.value == newVal }
log.warn("Product Line Option ID: $productLineOptionID")
//Add to targetValues List
targetValues += productLineOptionID.optionId
log.warn("Product Line Target Values: $targetValues")
getFieldByName("Product Line(s)").setDescription("Woooorrkkkkk")
} else {

1 answer

1 accepted

0 votes
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Mar 24, 2023

There is no reason for a for-loop to break anything. 

But how does the for-loop break your behaviour?

What errors are you getting?

What gets outputted to your log?

Hi Peter just validated that in fact you can use for loops in behaviors! 


When I was trying to grab the product line field I wasn't referencing the originated issue, but rather the destination issue. Corrected the below:

def productLineValue = contextIssue.getCustomFieldValue("Product Line(s)") as List

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events