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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.