Can't get this working out. Please help?
It says everyhing is allright but Issue level is not set after creation - nothing happens.
Hi @Arto Kovalainen,
You could make use of the following script (ScriptRunner):
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.security.IssueSecurityLevel
import com.atlassian.jira.issue.security.IssueSecurityLevelManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.servicedesk.api.requesttype.RequestTypeService
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
/*
* Define under which project the script should be applied
* When PROJ-1, PROJ-2, PROJ-n, the project key is PROJ
*/
def final PROJECT_KEY = "BSD"
/*
* Define which request type will be have the Security Level updated
*/
def final REQUEST_TYPE = "Computer support"
/*
* Define what the Security Level should be when issue gets created
* You MUST specify the security level as string and the script will
* search the the one provided exists and apply it when it is 'true'
*/
def final SECUTIRY_LEVEL = "Level B"
def issueManager = ComponentAccessor.getComponent(IssueManager)
def issueSecurityLevelManager = ComponentAccessor.getComponent(IssueSecurityLevelManager)
def issue = event.issue as Issue
MutableIssue mutableIssue = issueManager.getIssueByCurrentKey(issue.key)
ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
@WithPlugin("com.atlassian.servicedesk")
RequestTypeService requestTypeService = ScriptRunnerImpl.getPluginComponent(RequestTypeService)
def reqQ = requestTypeService.newQueryBuilder().issue(issue.id).build()
def reqT = requestTypeService.getRequestTypes(currentUser, reqQ)
def requestType = reqT.right.results[0].getName()
if (PROJECT_KEY.toUpperCase().equals(issue.projectObject.key.toUpperCase())) {
for (IssueSecurityLevel issueSecurityLevel in issueSecurityLevelManager.getAllIssueSecurityLevels()) {
if(REQUEST_TYPE.equals(requestType)) {
if (SECUTIRY_LEVEL.toUpperCase().equals(issueSecurityLevel.name.toUpperCase())) {
mutableIssue.setSecurityLevelId(issueSecurityLevel.id)
issueManager.updateIssue(currentUser, mutableIssue, com.atlassian.jira.event.type.EventDispatchOption.DO_NOT_DISPATCH, false)
}
}
}
}
The script above will run against a given project ONLY, defined as PROJECT_KEY.
In order to install it, please go to:
You will be presented with a form:
Save / Update the Listener
Now, when creating an issue under that particular Project, the issue created should have the Security Level described in the Script and no longer default specified in Jira Service Desk.
Hope the above helps.
Kind regards,
Rafael
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.