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

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
4,455,289
Community Members
 
Community Events
175
Community Groups

ScriptRunner Behaviour reseting select list value when read-only

Edited

The following Behaviour is used to restrict the available options in a select list 'Fruit'based on the security levels available to the user. The value of the field is editable *only* on the Create Screen, set using a second simple Behaviour that isn't of interest here. 

Editing an Issue (i.e. the Edit Screen) correctly shows the Fruit select list (read-only) with the correct value selected. However upon clicking 'Update' or 'Cancel' the view issue page reloads and the Fruit value has changed to equal the first (top) entry in the select list. 

I don't believe this happened prior to our recent upgrades to SRunner 5.5.7-jira8 and to Jira 8.3.1.

Aside from manually re-setting the Fruit to the original value, can anyone advise on why this happened or how to load the select list options in a cleaner/safer way.

 

Thanks

 

=====================

import com.atlassian.jira.issue.security.IssueSecurityLevel
import com.atlassian.jira.issue.security.IssueSecuritySchemeManager
import com.atlassian.jira.issue.security.IssueSecurityLevelManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.customfields.option.Options
import com.onresolve.jira.groovy.user.FormField

IssueSecurityLevelManager issueSecurityLevelManager = ComponentAccessor.getComponent(IssueSecurityLevelManager.class)
def optionsManager = ComponentAccessor.getOptionsManager()

//Get security levels for which the *current user* is registered
ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def securityLevels = issueSecurityLevelManager.getAllSecurityLevelsForUser(currentUser)
def securityLevelNames = securityLevels*.name

def customFieldManager = ComponentAccessor.getCustomFieldManager()

//hard coded reference to Fruit Select List
def cField = customFieldManager.getCustomFieldObjectsByName("Fruit")[0]
def fieldConfig = cField.getRelevantConfig(getIssueContext())
Options options = optionsManager.getOptions(fieldConfig)

//log.debug "options: " + options.toString()
Map<String, Object> optionsMap = options.findAll {
it.value in securityLevelNames // all options you wish to display in the select list
}.collectEntries{
[
(it.optionId.toString()): it.value
]
}

// Get a pointer
FormField fruitSelectList = getFieldByName("Fruit")
fruitSelectList.setFieldOptions(optionsMap)

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events