Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

script console setsecuritylevelid doesn't write to database?

Hello all,

I'm trying to write a listener that would set security level ID whenever there is an issue update or issue moved event. Essentially, if an issue is moved from a bug to non-bug, the security level should be set accordingly and vice-versa.

Since I'm not a coder, I usually just copy snippets of code and modify it for my purpose, however on this problem, I'm completely stumped. The listener doesn't work and when I try something simpler on script console such as:

import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor

def issueManager = ComponentAccessor.getIssueManager();
def issue = issueManager.getIssueObject("ABCD-123");
return issue.getSecurityLevelId();

The code above does return 10100, but when I check on the issue itself, the security level hasn't changed, i.e. still 10000. Does anyone know why the script is not writing the changes to the issue itself? Is it because it's a MutableIssue and there is another function to write the change to the database?

Thanks for any help.

1 answer

1 accepted

1 vote
Answer accepted

Hi Jeff,

Your code is just setting the property on the object, but it is not persisted. You have to do that yourself, in the same way you would do an edit or a transition if using the GUI.

There are various methods to do this, here is one:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.UpdateIssueRequest

def issueManager = ComponentAccessor.issueManager
def issue = issueManager.getIssueObject("JRA-9")

def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
issueManager.updateIssue(user, issue, UpdateIssueRequest.builder().sendMail(false).build())

Thanks Jamie. That works. I'll try this method on listener as well.

Hi Jamie,

Thanks to your suggestion, I have this script listerner which sort of work. It is set to listen to "Issue Updated" and "Issue Moved":

import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.event.issue.IssueEvent

def issue = event.issue as MutableIssue
def issueManager = ComponentAccessor.issueManager

if (issue.getIssueType() == "Bug" {
else if (issue.getIssueType() != "Bug") {

def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
issueManager.updateIssue(user, issue, UpdateIssueRequest.builder().sendMail(false).build())

The problem is the script listener runs on the first time the issue is updated or moved. The subsequent update/move on the same issue seems to have fallen on deaf ears. Is this a known issue or maybe there is something wrong with my script?

Hi Jeff... your code is wrong. The "else" statement will always be true.


if ( == "Bug") {
else {

Hi Jamie,

Thanks for the response. The code is indeed mistaken. I blame it on too much Python recently :)

However, the problem still stands. I used a simple script console to


and check the jira issue, it is indeed updated the first time. But if I run in script console again:


This doesn't seem to update the issue anymore. It looks like updateIssue can only be run once. Is there something wrong with my code or maybe I need to run a slightly different updateIssue call the second time?

I don't recognise this... you can run updateIssue as many times as you want. Are there definitely no errors? 

Is it possible that after changing the sec level the current user has no permissions to that issue? Then you would get an error I would imagine.

Can you check the issue update history from the UI? Does it show both updates?

Hi Jamie,

It is indeed very odd. When I look at the issue's history, the script updated the security level, but as soon as that happens, the security level is reverted back to the original (by the same user). Enabling the log doesn't show anything out of the ordinary.

After a little of googling, I've decided to go with which works but may be deprecated in the future. IssueUpdate seems to have some weird problems associated with it, such as:

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Apps & Integrations

Partner Webinar Opportunities: January 2022

Hi everyone 👋, I really like the format of the webinar opportunities summary that @Jimmy Seddon posts monthly on the Welcome Centre group. It's a great place to go to check that you didn...

42 views 0 4
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you