Not sure why this documentation is so hard to find. I simply want to update a custom field to a value.
This is in Jira Cloud. How can I set the customfield_10121 to the dropdown value of ENV1?
def customFieldName = 'customfield_10100'
def result = get("/rest/api/2/issue/${issue.key}?fields=${customFieldName}")
.header('Content-Type', 'application/json')
.asObject(Map)
def type = result.body.fields[customFieldName].value
if (type == 'New Functionality') {
def setEnvironment = put("/rest/api/2/issue/${issue.key}")
.header("Content-Type", "application/json")
.body([
fields:[
customfield_10121: 'ENV1'
]
])
.asString()
}
Hi,
I suppose you get Could not find valid 'id' or 'value' in the Parent Option object error.
Just update this line:
fields: [
customfield_10121:[value: 'ENV1']
]
I found the answer in another snippet in the scripting console. You need to find the option value first.
// Specify the name of the select list field to set
def selectListFieldName = 'Assigned Environment'
// Get the Custom field to get the option value from
def customField = get("/rest/api/2/field")
.asObject(List)
.body
.find {
(it as Map).name == selectListFieldName
} as Map
// Check if the custom field returns a valid field and is not null
assert customField != null : "Cannot find custom field with name of: ${selectListFieldName}"
def result = put("/rest/api/2/issue/${issue.key}")
.header('Content-Type', 'application/json')
.body([
fields: [
(customField.id):[value: "ENV1"] as Map
]
])
.asString()
if (result.status == 204) {
return "The ${customField.name} select list field was successfully updated on the ${issue.key} issue"
} else {
return "${result.status}: ${result.body}"
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.