The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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)
Hello everyone, Hope everyone is safe! A few months ago we posted an article sharing all the new articles and documentation that we, the AMER Jira Service Management team created. As mentioned ...
Connect with like-minded Atlassian users at free events near you!
Find an eventConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.
Host an eventYou're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events