JIRA Cloud-Update Select List Field via Rest API Edited

In JIRA Cloud, I have a Script Listener set up for Issue Updates. I'm trying to update a select list field through the Rest API using ScriptRunner. I'll paste my script below, but basically if a issue has a Label of 'OnHold' then the custom field PMO Sprint Status is set to 'On Hold.' 

def projectKey = 'TRAIN'

if (issue.fields.project.key != projectKey) {
return
}

def pmoSprintStatus = ""

if (issue.fields.labels.contains("OnHold")) {
if (issue.fields.customfield_10747 != "OnHold") {
pmoSprintStatus = "OnHold"
}
} else {
if (issue.fields.customfield_10747 == "OnHold") {
pmoSprintStatus = "Active"
}
}

if (pmoSprintStatus != "") {
put("/rest/api/2/issue/${issue.key}")
.queryString("overrideScreenSecurity", true)
.header('Content-Type', 'application/json')
.body([
fields: [
customfield_10747 : { value: pmoSprintStatus}

]
])
.asString()  
}

The part in bold seems to be where the problem is. No matter how I format that line, I always get the following error.

2017-10-10 06:48:38.926 WARN - PUT request to /rest/api/2/issue/TRAIN-8 returned an error code: status: 400 - Bad Request
body: {"errorMessages":[],"errors":{"customfield_10747":"Could not find valid 'id' or 'value' in the Parent Option object."}}
2017-10-10 06:48:38.929 INFO - PUT /rest/api/2/issue/TRAIN-8 asString Request Duration: 620ms

Any thoughts on what I"m missing/doing wrong? This is JIRA Cloud, updating a select list single choice field via REST API. Thanks!

 

1 answer

1 accepted

This widget could not be displayed.

Hi @Keri Hudson,

I'm pretty sure what you need to change is

customfield_10747 : { value: pmoSprintStatus}

to be:

customfield_10747 : [ value: pmoSprintStatus ]

because in Groovy both maps and lists use square brackets.

Let me know if that doesn't fix things!

Thanks,
Jon

@Jon Bevan

Requirement - 

I want to update a drop down field based on certain condition.

 I am writing the escalation service in which i have enabled the condition in JQL, and now i want to update the issues that are the result of the JQL.

 I have a field named -ReviewRecommendation which has 4 drop down values - None,Hold,Accept, Reject.

 This field is getting set to None by JMWE add-on to "None" value.

 I have one more field named "Due date", now i have written the JQL as - 

 project = PRIYAN and "Review Recommendation"=None and "due" <now()

 Now for  all the issues which are result set of the above JQL, the field "ReviewRecommendation "should be updated to "Accept".

Could you provide me the script for my requirement.

Below is my script which is not working, please help me in resolving it.

def issueKey = issue.key

def ReviewRecommendation = ""

if (issue.fields.customfield_26872 =="None")
{
ReviewRecommendation = "Accept"
}

def result = put("/rest/api/2/issue/${issue.key}")
.queryString("overrideScreenSecurity", true)
.header('Content-Type', 'application/json')
.body([
fields: [
customfield_26872 : [ value: ReviewRecommendation]

]
])
.asString()

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

126 views 1 3
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you