Forums

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

Not able to update "Security Level" field

Pushpkant Garg
Contributor
August 22, 2019

I am trying to update the "Security Level" field based on the Team selected by the user.

Here is the code:

def issueKey = event.issue.key
def customFieldName = 'customfield_11048'
def result = get("/rest/api/2/issue/${issueKey}?fields=${customFieldName}")
.header('Content-Type', 'application/json')
.asObject(Map)
Map team = null

import org.apache.log4j.Level
import org.apache.log4j.Logger

def myLog = Logger.getLogger("com.onresolve.jira.groovy")
myLog.setLevel(Level.DEBUG)
if (result.status == 200) {
team = (Map)result.body.fields[customFieldName]

myLog.debug "team ......"+team.value
if(team.value == "Asia"){
def result1 = put("/rest/api/2/issue/${issueKey}")
.header('Content-Type', 'application/json')
.body([
fields: [
security : [
name : "Asia"
],
]
])
.asString()
}

if(team.value == "Africa"){
def result1 = put("/rest/api/2/issue/${issueKey}")
.header('Content-Type', 'application/json')
.body([
fields: [
security : [
name : "Africa"
],
]
])
.asString()
}

if(team.value == "Europe"){
def result1 = put("/rest/api/2/issue/${issueKey}")
.header('Content-Type', 'application/json')
.body([
fields: [
security : [
name : "Europe"
],
]
])
.asString()
}

if(team.value == "Iberoamerica"){
def result1 = put("/rest/api/2/issue/${issueKey}")
.header('Content-Type', 'application/json')
.body([
fields: [
security : [
name : "Iberoamerica"
],
]
])
.asString()
}

if(team.value == "ILS"){
def result1 = put("/rest/api/2/issue/${issueKey}")
.header('Content-Type', 'application/json')
.body([
fields: [
security : [
name : "ILS"
],
]
])
.asString()
}

if(team.value == "North America"){
def result1 = put("/rest/api/2/issue/${issueKey}")
.header('Content-Type', 'application/json')
.body([
fields: [
security : [
name : "North America"
],
]
])
.asString()
}

if(team.value == "Repairs"){
def result1 = put("/rest/api/2/issue/${issueKey}")
.header('Content-Type', 'application/json')
.body([
fields: [
security : [
name : "Repairs"
],
]
])
.asString()
}

if(team.value == "Russia"){
def result1 = put("/rest/api/2/issue/${issueKey}")
.header('Content-Type', 'application/json')
.body([
fields: [
security : [
name : "Russia and Azal"
],
]
])
.asString()
}

if(team.value == "Azal"){
def result1 = put("/rest/api/2/issue/${issueKey}")
.header('Content-Type', 'application/json')
.body([
fields: [
security : [
name : "Russia and Azal"
],
]
])
.asString()
}

myLog.debug "Team : "+team.value

}

Script is working fine but not updating the "Security Level" field.

Log Snippet.

2019-08-23 04:22:51.015 INFO - Serializing object into 'interface java.util.Map'
2019-08-23 04:22:52.036 INFO - GET /rest/api/2/issue/FB-5?fields=customfield_11048 asObject Request Duration: 4241ms
2019-08-23 04:22:52.058 DEBUG - team ......Russia
2019-08-23 04:22:52.630 WARN - PUT request to /rest/api/2/issue/FB-5 returned an error code: status: 400 - Bad Request
body: {"errorMessages":[],"errors":{"security":"Security level name 'Russia and Azal' is not valid"}}
2019-08-23 04:22:52.631 INFO - PUT /rest/api/2/issue/FB-5 asString Request Duration: 415ms
2019-08-23 04:22:52.632 DEBUG - Team : Russia
2019-08-23 04:22:52.633 INFO - Run script completed

I have got all the necessary permission. 

Kindly help me where I am wrong.

2 answers

1 accepted

0 votes
Answer accepted
Pushpkant Garg
Contributor
August 23, 2019

User Executing the Transition was not part of the Security Level.

0 votes
Andrew
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.
August 22, 2019

Hi @Pushpkant Garg ,

I see:

Security level name 'Russia and Azal' is not valid

Error happen only for that name or for any others?

B.R.

Pushpkant Garg
Contributor
August 23, 2019

Hi @Andrew 

I got the solution. I was not part of the Security Level. After adding myself to the Security Level, script works fine.

Like Andrew likes this

Suggest an answer

Log in or Sign up to answer