Missed Team ’24? Catch up on announcements here.

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

set issue security based on a custom field

Consulente Atlassian March 21, 2022

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 ?

Schermata 2022-03-21 alle 16.32.07.pngSchermata 2022-03-21 alle 16.32.15.png

2 answers

2 votes
Brant Schroeder
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 21, 2022
0 votes
Deleted user March 22, 2022
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)

 

Schermata 2022-03-22 alle 08.41.38.png

 

@Brant Schroeder  

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.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events