Forums

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

For loops in Behaviors?

Bellina Bui
March 24, 2023

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 com.atlassian.jira.issue.search.SearchProvider
import static org.apache.commons.collections.CollectionUtils.*
final productLine = "Product Line(s)"
if (getBehaviourContextId() == "create-epic-button") {
//Testing
getFieldByName("Summary").setFormValue("Testing")
// 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())
parentLink.setFormValue("${contextIssue.key}")
//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

Suggest an answer

Log in or Sign up to answer
0 votes
Nic Brough -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 Champions.
October 6, 2017

I don't think it's this, but is the user part of the rule for the new level?   Can they change the security level to the desired one by editing the issue in the UI?

Are you making other changes to the issue in the script?  If so, are they working?

Alejandro Chavarria
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 9, 2017

There is no option to run under the context of a specific user, so I assume the post function will run under the current user's context (see attached screenshot to see what it looks like to define this workflow post function).

Also, I tested this as an administrator (full project permissions) and still no luck. I'm completely at a loss. Any help is very much appreciatedCapture.PNG

TAGS
AUG Leaders

Atlassian Community Events