I'm trying to populate a select list (on the create issue screen) populated with security levels . It is not appropriate to simply show the Security Level field (I understand that I can't simply rename it). I haven't been able to find a custom field type suitable.
Any help appreciated,
Thanks
You'll need to write a new field type to do that if you want to directly use the security levels. Another option might be to create a standard select list and then script something that synchronises it with the security level list.
Out of curiosity, why do you need this? I can think of only one use for it, and I'd probably take a different approach for that myself, but I'm keen to hear of other use-cases!
Hi Nick, thanks for the very swift reply!
Here's a long-winded attempt at an explanation!
On our other system the security level is deliberately hidden, set automatically on issue creation according to the user's group membership (done via script runner). A custom field ('Group') is then autopopulated with the security level. The custom field naming has much more meaning to our users than 'Security Level'.
I would like to mimic this convention in the new Jira instance, whereby the user is able to select a Group value from a custom select list (choices being the security levels available), and then the security level is automatically set to this value following creation.
Is this the most up-to-date / suitable guide for custom field creation?
https://developer.atlassian.com/jiradev/jira-platform/guides/fields/tutorial-creating-a-custom-field-type
Thanks again
You could use a behaviour for this to create the options and then restrict the list.
Adapting the last example here could work for you.
I'd follow some of the examples from our documentation and see if behaviours would work for you.
You can get the various security levels for that project by using (for some reason I can't post formatted code so I've added it as below):
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.Issueimport com.atlassian.jira.issue.security.IssueSecuritySchemeManagerdef issueSecurityLevelManager = ComponentAccessor.getIssueSecurityLevelManager()def issueSecuritySchemeManager = ComponentAccessor.getComponent(IssueSecuritySchemeManager)def srcProject = underlyingIssue.getProjectObject()def issueSecurityScheme = issueSecuritySchemeManager.getSchemeFor(srcProject)if (! issueSecurityScheme) {log.warn("No issue security scheme defined for project ${srcProject.name}".toString())return null}def securityLevels = issueSecurityLevelManager.getIssueSecurityLevels(issueSecurityScheme.id)def securityLevelNames = securityLevels*.name
Hmm. I'm not sure I understand that. Could you not set the security level automatically on create, and then place the security level on edit screens for them to edit later?
That would reduce the problem to "we don't like the name 'security level'" which is completely understandable. But you could put explanatory test with it, or, with a little "development", create a "translation" for your system that uses a different phrase (I say "development", but it's more "copy existing and do a search on some plain text")
It's important that the security level is *chosen* on creation I'm afraid. I've looked into a translation add-on* for Jira but wasn't able to work out how to use it with fields on the create issue form e.g. security level, issue.
*https://marketplace.atlassian.com/plugins/com.atlassian.translations.jira.inproduct/server/overview
does this mean the script is run every single time any issue is updated? Is that practical?
Thanks Adam, I'm now able to populate a custom field with security levels using the code:
import com.atlassian.jira.security.groups.GroupManagerimport com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.Issueimport com.atlassian.jira.issue.MutableIssueimport com.atlassian.jira.issue.security.IssueSecurityLevelimport com.atlassian.jira.ComponentManagerimport com.atlassian.jira.issue.security.IssueSecuritySchemeManagerimport com.atlassian.jira.issue.security.IssueSecurityLevelManagerimport com.atlassian.jira.component.ComponentAccessorIssueSecuritySchemeManager issueSecuritySchemeManager = ComponentAccessor.getComponent(IssueSecuritySchemeManager.class)IssueSecurityLevelManager issueSecurityLevelManager = ComponentAccessor.getComponent(IssueSecurityLevelManager.class)def customFieldManager = ComponentAccessor.getCustomFieldManager()def cField= customFieldManager.getCustomFieldObjectByName("Etest")def issue = event.issue as Issuedef srcProject = issue.getProjectObject()def issueSecurityScheme = issueSecuritySchemeManager.getSchemeFor(srcProject)def optionsManager = ComponentAccessor.getOptionsManager()def issueService = ComponentAccessor.getIssueService()if (! issueSecurityScheme) {log.warn("No issue security scheme defined for project ${srcProject.name}".toString())return null}def securityLevels = issueSecurityLevelManager.getIssueSecurityLevels(issueSecurityScheme.id)def securityLevelNames = securityLevels*.namelog.debug "sec level names: " + securityLevelNamesdef fieldConfig = cField.getRelevantConfig(issue)def currentOptions = optionsManager.getOptions(fieldConfig)def newSecurityLevelNames = []log.debug " current options: " + currentOptionsfor (i in securityLevelNames){ log.debug i if (!currentOptions.toString().contains(i)){ log.debug " new sec level " + i + " found " newSecurityLevelNames.add(i) }}for (i in newSecurityLevelNames){ def newSeqId = currentOptions*.sequence.max() - 1optionsManager.createOption(fieldConfig, null, newSeqId, i.toString())}
The list of security levels will be static so I will look to adapt this script to be run from the console as part of the Jira deployment, rather than running as a listener. Or is there any way I can setup the listener to trigger when a new security level (or the config is changed) is added?
What does the remaining code from the example do? Is this to update the create issue form on the fly?
def issueInputParameters = IssueService.newIssueInputParameters() issueInputParameters.with { addCustomFieldValue(faveFruitFld.idAsLong, option.optionId.toString()) addCustomFieldValue(faveFruitOtherFld.idAsLong, null) }def updateValidationResult = issueService.validateUpdate(currentUser, issue.id, issueInputParameters) if (updateValidationResult.isValid()) { issueService.update(currentUser, updateValidationResult) } else { log.warn("Failed to update issue: ${issue.key}: ${updateValidationResult.errorCollection}") }
Thanks for your help
It looks like you're new here. Sign in or register to get started.