Forums

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

Unable to to set fixVersion id by Script Runner

馬場泰年 July 28, 2022

I want to set an id for the fixVersion by a script.
It is able to set by REST API using Python' s requests method as following,

#------

url = "https://xxxxxxx.atlassian.net/rest/api/3/issue/TTES3-6"

auth = HTTPBasicAuth("xxxx","xxxxxx")

headers = {
"Accept": "application/json",
"Content-Type": "application/json"
}

payload = json.dumps( {
"fields": {
"fixVersions": [{"id": "10091"} ],
}})

response = requests.request(
"PUT",
url,
data=payload,
headers=headers,
auth=auth
)
print (response.status_code)


But it is unable to set using ScriptRunner's Script Console, 
#------
def result = put("/rest/api/3/issue/TTES3-6")
.header('Content-Type', 'application/json')
.body([
     fields:[ fixVersions:[{id: '10091'}]

     ]
])
.asObject(Map)
return result.status
#-----
Return code is 204, but the fixVersion field becomes blank.
(Another field like summary or custom field seems to be able to set value using same method....)
What's wrong?

1 answer

0 votes
Joseph Chung Yin
Community Champion
July 28, 2022

@馬場泰年 -

You should take a look at ScriptRunner script example using Groovy to set issue values - https://docs.adaptavist.com/sr4jc/latest/features/script-console/script-examples

You may also want to contact Adaptavist for support directly.

Best, Joseph Chung Yin

Jira/JSM Functional Lead, Global Infrastructure Applications Team

Viasat Inc.

馬場泰年 July 29, 2022

@Joseph Chung Yin 
Dear Mr. Yin.
Thank you for your advice.
I didn't understand how to convert JSON to Map format  used on Groovy.

//re-wrote script
def result = put("/rest/api/3/issue/TTES3-6")
.header('Content-Type', 'application/json')
.body([
     fields:[

          fixVersions:[ [id: '10091'] as Map ]

     ]
])
.asObject(Map)
return result.status

//It's OK. Thanks.

Joseph Chung Yin
Community Champion
July 29, 2022

@馬場泰年 -

Why do you want to convert it to a map?  I don't believe it is necessary.  Take a looking at the page that I mention to you in the previous posting and look at the script example "Update an Issue".

Best, Joseph

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events