Update Sprint Field in Cloud with Scriptrunner Post Function

Hello,

I'm trying to copy the values of a few fields in JIRA Cloud, using a ScriptRunner workflow post function. I got the following code to work to copy Story Points to a customfield:

def result = put("/rest/api/2/issue/${issueKey}")
.header('Content-Type', 'application/json')
.body([
fields: [
customfield_10746: issue.fields["customfield_10119"],
]
])
.asString()

However, when I tried to also copy the Sprint field to a custom field called Baseline Sprint, by adding this line:
customfield_10739: issue.fields["customfield_10115"] I get the following error:

2017-10-05 05:56:09.734 WARN - PUT request to /rest/api/2/issue/TRAIN-17 returned an error code: status: 400 - Bad Request
body: {"errorMessages":[],"errors":{"customfield_10739":"Operation value must be a string"}}
2017-10-05 05:56:09.851 INFO - PUT /rest/api/2/issue/TRAIN-17 asString Request Duration: 2218ms
2017-10-05 05:56:09.852 INFO - Run script completed 

Any ideas on how to do this? Again this is JIRA Cloud. Thanks!

 

 

1 answer

I ended up doing this through a script listener, which pulls the most recent sprint from the Sprint field & copies it to a field called 'Current Sprint.' This needs some cleaning up, but it's working for now:

 

def projectKeys = ['TRAIN', 'MEST', 'CONS', 'FB', 'CAMP']

if (!(issue.fields.project.key in projectKeys)) {
return
}

def issueKey = issue.key
def thing = issue.fields.customfield_10115.last().tokenize(',')
def latest_sprint = thing[3].tokenize('=')[1]

def result = put("/rest/api/2/issue/${issueKey}")
.header('Content-Type', 'application/json')
.body([
fields: [
customfield_10752: latest_sprint
]
])
.asString()

Suggest an answer

Log in or Join to answer
Community showcase
Teodora [Botron]
Published Thursday in Marketplace Apps

Jira Inferno: The Nine Circles of Jira Administration Hell

If you spend enough time as a Jira admin - whether you are managing a single, mid-sized instance, a large enterprise one or juggling multiple instances at once - you will eventually find yourself in ...

298 views 0 12
Read article

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot