I am trying to do set issue security based on a custom field. I have a custom field that is called Assignment Group. It is a custom field of type Group Picker from Jira. When an issue transits from To Do to In Progress I want to put a post-function in the workflow so that the issue takes the security level equal to the value of the Group Picker. There are three security levels: level-1, level-2 and level-3. The Assignee Groups are three and they are called in the same way: level-1, level-2 and level-3. I do not know how Script Runner can copy the value of the Assignee Group field and put it in the Issue Security Level field. Can anyone help me ?
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.security.IssueSecurityLevelManager
import com.atlassian.jira.issue.security.IssueSecuritySchemeManager
import com.atlassian.crowd.embedded.impl.ImmutableGroup
def issueSecuritySchemeManager = ComponentAccessor.getComponent(IssueSecuritySchemeManager)
def issueSecurityLevelManager = ComponentAccessor.getComponent(IssueSecurityLevelManager)
def customFieldManager = ComponentAccessor.customFieldManager
// Change it to your Group Picker field name
def groupPicker = customFieldManager.getCustomFieldObjectsByName("Gruppo Assegnatario").first()
def group = (issue.getCustomFieldValue(groupPicker) as ArrayList<ImmutableGroup>).first()
def project = issue.getProjectObject()
def issueSecurityScheme = issueSecuritySchemeManager.getSchemeFor(project)
def securityLevelID = issueSecurityLevelManager.getIssueSecurityLevels(issueSecurityScheme.id).find { it ->
// since the group name is equal to the security level name
it.name == group.name
}?.id
issue.setSecurityLevelId(securityLevelID)
thank you for your reply, I am making many attempts, as I said I do not know Script Runner and I am learning. With the help of many other people I was able to put this code together. Which works, in the sense that I can now write the value. But it happens that when I make the transition in the Security Level field I am left with the "previous" value and I don't understand why.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.