Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Setting issue security level based on issue type value using scriptrunner

John Diaz January 26, 2022

I'm trying to set a security level value based on the issue type selected using ScriptRunner Listener. 

I think this somewhat similar to this question but using issue type instead  of custom field - https://community.atlassian.com/t5/Adaptavist-questions/Setting-issue-security-level-based-on-custom-field-value-using-a/qaq-p/1592935

My project uses four issue types: Bug, Task, Epic and Story.  What I'm trying to achieve using the ScriptRunner is if someone creates a ticket using Bug or Task issue type then it will automatically set the Security Level to Security A. If Epic or Story is selected then it will automatically set the Security Level to Security B.

How do I do that using ScriptRunner?  I don't know if I should be creating a Listener or using Post Function script (e.g. set issue security level depending on condition). My knowledge of groovy scripting is at the bottom of the totem pole so I would need someone to help me write the script and I can plug and play. 

1 answer

1 accepted

2 votes
Answer accepted
Kian Stack Mumo Systems
Community Champion
January 26, 2022

@John Diaz

 

You can use a listener or a post function, either would work!

 

Here is an example of a listener:

 

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption

def customFieldManager = ComponentAccessor.getCustomFieldManager()

if(issue.issueTypeObject.name == "Bug" || issue.issueTypeObject.name == "Task"){
issue.setSecurityLevelId(10000);

}
else{
issue.setSecurityLevelId(10001);
}




def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueManager = ComponentAccessor.getIssueManager()

issueManager.updateIssue(user,issue,EventDispatchOption.DO_NOT_DISPATCH,true)



Credit to @Ravi Sagar _Sparxsys_, his code was the basis for the answer!

You'll have to customize the two id's depending on your instance.

John Diaz January 26, 2022

@Kian Stack Mumo Systems  Thank you so much!  Plug and play worked.  

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events