Load default security level of schema with a behaviour (scriptrunner)

alozores July 25, 2018

Hi,

I have the next behaviour to define the security level and it works correctly but I need that if it doesn´t meet the conditions select the default security level defined in the scheme.

The code:

import com.atlassian.jira.component.ComponentAccessor

if (getActionName () == "Create") {
    finalSecurity level = "Deployment"

    final secLevel = ComponentAccessor.getIssueSecurityLevelManager (). getUsersSecurityLevels (getIssueContext (). projectObject, ComponentAccessor.getJiraAuthenticationContext (). getLoggedInUser ()). findAll {
        it.name.contains (securityLevel)
    }

    if (! secLevel.id.empty) {
        getFieldById ("security"). setFormValue (secLevel.id)
        getFieldById ("security"). setReadOnly (true)
    }
}

The function that I think I need is "getDefaultSecurityLevel":

https://docs.atlassian.com/software/jira/docs/api/7.1.6/com/atlassian/jira/issue/security/IssueSecurityLevelManager.html#getDefaultSecurityLevel-com.atlassian.jira.project.Project-
but I dont know how to apply it.

Could you help me?

The version of Jira that I use is 7.6.4 and the scriptrunner version is 5.3.16.

Thank you very much.

Greetings,
Alex

2 answers

0 votes
Alex López August 16, 2018

Hi,

Finally works with this code: 

import com.atlassian.jira.component.ComponentAccessor

if (getActionName() == "Create") {

if (issueContext.issueType.name == "Deployment"){

final level= "Deployment"

final secLevel = ComponentAccessor.getIssueSecurityLevelManager().getUsersSecurityLevels(getIssueContext().projectObject,ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()).findAll {
it.name.contains(level)
}

if (!secLevel.id.empty){
getFieldById("security").setFormValue(secLevel.id)
getFieldById("security").setReadOnly(true)
}
}
else {
final project= getIssueContext().getProjectObject()
final defaultSecurityLevel = ComponentAccessor.getIssueSecurityLevelManager().getDefaultSecurityLevel(project)

getFieldById("security").setFormValue(defaultSecurityLevel)
getFieldById("security").setReadOnly(false)
}
}

Thanks,

Alex

0 votes
Alex López August 1, 2018

Any idea?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events