You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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.IssueManagerimport com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.jql.parser.JqlQueryParserimport com.atlassian.jira.issue.search.SearchProviderimport static org.apache.commons.collections.CollectionUtils.*final productLine = "Product Line(s)"if (getBehaviourContextId() == "create-epic-button") {//TestinggetFieldByName("Summary").setFormValue("Testing")// Get some componentsdef jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)def searchProvider = ComponentAccessor.getComponent(SearchProvider)def issueManager = ComponentAccessor.issueManagerdef user = ComponentAccessor.jiraAuthenticationContext.loggedInUserdef optManager = ComponentAccessor.getOptionsManager()//Parent Linkdef parentLink = getFieldByName("Parent Link")def parentLinkValue = parentLink.getValue()def contextIssue = issueManager.getIssueObject(getContextIssueId())parentLink.setFormValue("${contextIssue.key}")//Product Linedef productLineName = ComponentAccessor.customFieldManager.customFieldObjects.findByName(productLine) //Get Objectsdef productLineList = getFieldByName(productLine).getValue() as List //Get Values as Listlog.warn("Product Line List: $productLineList")//Get Product Line Field Configdef productLineConfig = productLineName.getRelevantConfig(contextIssue)log.warn("Product Line Field Configuration: $productLineConfig")//Get Product Line Field Value Optionsdef 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 variabledef newVal = i.toString()//Get Product Line Option IDdef productLineOptionID = productLineOptions. find { it.value == newVal }log.warn("Product Line Option ID: $productLineOptionID")//Add to targetValues ListtargetValues += productLineOptionID.optionIdlog.warn("Product Line Target Values: $targetValues")getFieldByName("Product Line(s)").setDescription("Woooorrkkkkk")}} else {}
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.