Hi All,
I am using Scriptrunner -Script Listener code to update a child select list to a value depending on what is selected in parent select list. I get an error stating " This is in Jira Cloud.
PUT request to /rest/api/2/issue/L2-12 returned an error code: status: 400 - Bad Request body: {"errorMessages":[],"errors":{"customfield_10064":"Specify a valid 'id' or 'name' for Finance Type"
Code snippet given below. It is failing in the PUT request. Any help is much appreciated.
def issueKey = issue.key
def financeType='Finance Type'
// Fetch the issue object from the key
def issue = get("/rest/api/2/issue/${issueKey}")
.header('Content-Type', 'application/json')
.asObject(Map)
.body
// Get all the fields from the issue as a Map
def fields = issue.fields as Map
// 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 == 'Feature ArcheType'
} as Map
//assert customField : "Failed to find custom field with given name"
// Extract and store the option from the custom field
def value = (fields[customField.id] as Map)?.value
//assert value : "${value}"
// Return the option value
def finance = null
if(value == "Analysis")
{
finance = "Opex"
}else {
finance="Capex"
}
def result = put("/rest/api/2/issue/${issueKey}")
.header('Content-Type', 'application/json')
.body([ fields:[
customfield_10064: [{value :"CAPEX"}]
//(financeType) : finance
]
])
.asString()
Welcome to the Atlassian Community!
This suggests that customfield 10064 is a select list that does not have an option for CAPEX.
Well, customfield 10064 is a select list with dropdown values as CAPEX and OPEX.
I am just trying to set this field by default to CAPEX or OPEX depending on the value selected in another Select list/custom field.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry, missed a bit out.
I don't think your field has an option for {CAPEX}. I think it does for CAPEX - try removing the braces.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The script actually fails here
customfield_10064: [{value :"CAPEX"}] with an error "Specify a Valid Id or Name"
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.