Forums

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

I am using Scriptrunner-script listener for cloud and stuck with an error Specify a valid 'id' or 'n

Priya_ThirumalaiKrishnamoorth February 14, 2023

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()

2 answers

0 votes
Nic Brough -Adaptavist-
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.
February 14, 2023

Welcome to the Atlassian Community!

This suggests that customfield 10064 is a select list that does not have an option for CAPEX.

Priya_ThirumalaiKrishnamoorth February 16, 2023

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. 

Nic Brough -Adaptavist-
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.
February 17, 2023

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.

0 votes
Priya_ThirumalaiKrishnamoorth February 14, 2023

The script actually fails here

 

customfield_10064: [{value :"CAPEX"}] with an error "Specify a Valid Id or Name"

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events