Forums

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

Set issue security level post function based on JIRA SD Customer Request type?

Arto Kovalainen
Contributor
February 12, 2019

Can't get this working out. Please help?

It says everyhing is allright but Issue level is not set after creation - nothing happens.

 

Screenshot 2019-02-12 at 12.51.41.pngScreenshot 2019-02-12 at 12.51.28.png

1 answer

1 accepted

1 vote
Answer accepted
Rafael Pinto Sperafico
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 12, 2019

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:

  • Jira administration >> Add-ons >> ScriptRunner >> Script Listeners
  • Add a new item

You will be presented with a form:

  • Under Events, type in "Issue Created"
  • Under Condition, place the script above making the changes suggested
  • Under Event, select "Issue Created"

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

Arto Kovalainen
Contributor
February 14, 2019

Works perfectly. Rafa rules!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events