Proper way to update Security Level in a groovy listener? Edited

Need help with the subject, code runs inside Create Issue SR listener. Spent substantial time trying to break through various ways to update an issue within a context of scriptrunner listener, to no avail. Looks like the best practice has evelved multiple time over last few years. The code doesn't complain during runtime, yet fails to update security level. Thanks for your suggestions.

... [set value to secLvlId]

def iSvc = ComponentAccessor.issueService
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def params = iSvc.newIssueInputParameters()
params.setSecurityLevelId(seclvlId)
def validationRes = iSvc.validateUpdate(user, issue.id, params)
if (validationRes.isValid()) {
  iSvc.update(user, validationRes)
} else {
  log.warn """Unable to perform the issue security level update to $seclvlId!
  Issue:$issue
  Error:$validationRes.errorCollection"""
}

1 answer

0 vote

Is "seclvlId" the security level id as a long? Where are you getting the id from? Does the user who created the triggered the listener have permissions to update the security level?

If some of these things had happened I would have expected to have seen a message in the logs. Is there nothing in the logs?

It is not a long, no, just a regular constant assigned to it, like 10101. I am an admin, so I believe both questions on a user are yes. Nothing in the logs, except my messages from log.warn.

That should be ok, as long as that security level id exists in JIRA. Groovy will convert it to a long.

You mention you see you log.warn in the logs. Do you see the error? You previously mentioned you didn't but just wanted to check. 

Could you please post your full script? Then I'll try it out.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Tuesday in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

119 views 0 4
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you