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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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
Community showcase
Published in Confluence

👁‍🗨 Confluence Team planning dashboard_Atlympics 🌈

Hi Atlassian's, How is your journey with #Atlympics 2021 so far....excited! Me too, same excitement. Here's my typical team planning and vision dashboard which I used to share to my management and ...

101 views 1 5
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you