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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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 Marketplace Apps & Integrations

Do Not Lose your Customer’s Trust

Missing deadlines is one of the biggest problems every team lead wants to avoid when dealing with managed services. When the customer contracts your company to help with IT services it is expected th...

24 views 0 0
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