Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,456,637
Community Members
 
Community Events
176
Community Groups

Scriptrunner listener log returns "data was not an object"

I have assembled a script listener to copy the contents of a system field (Assignee) to a custom Field (Assigned To) when an event (Issue Updated) is triggered. I have limited it to one project (ATS) and would like it to only run against the issue that triggered the event.

I have assembled the script from two available via Adaptavists website, the Copy Custom Field Values and the Calculate Custom Field On Issue Update. Using the Copy Custom Field Values wants to run agains all issues that meet the JQL query on the second line. The Calculate Custom Field On Issue Update only runs against the issue that triggered it and works wonderfully elsewhere on our instance.

 

The script 'completes successfully,' but leaves this error:

2018-01-30 22:16:52.816 INFO - Serializing object into 'interface java.util.Map'
2018-01-30 22:16:52.822 INFO - GET /rest/api/2/issue/ATS-1544 asObject Request Duration: 1029ms
2018-01-30 22:16:53.372 INFO - Serializing object into 'interface java.util.List'
2018-01-30 22:16:53.613 INFO - GET /rest/api/2/field asObject Request Duration: 759ms
2018-01-30 22:16:54.220 WARN - PUT request to /rest/api/2/issue/ATS-1544 returned an error code: status: 400 - Bad Request
body: {"errorMessages":[],"errors":{"customfield_14047":"data was not an object"}}
2018-01-30 22:16:54.222 INFO - PUT /rest/api/2/issue/ATS-1544 asString Request Duration: 548ms

 Here is my script:

package com.adaptavist.sr.cloud.samples.events

def sourceFieldName = 'Assignee'
def targetFieldName = 'customfield_14047' //'Assigned To'
def result = get("/rest/api/2/issue/${issue.key}" )
    .header('Content-Type', 'application/json')
    .asObject(Map)

// We retrieve a list of all fields in this JIRA instance
def fields = get("/rest/api/2/field")
    .asObject(List)
    assert fields.status == 200

List<Map> allFields = fields.body


// Now we lookup the field IDs
Map sourceField = allFields.find { it.name == sourceFieldName }
Map targetField = allFields.find { it.name == targetFieldName }

put("/rest/api/2/issue/${issue.key}")
    .header("Content-Type", "application/json")
    .body([
    fields:[
    (targetFieldName): sourceField.key
    ]
])
   .asString()

2 answers

Hey

 

try this:

package com.adaptavist.sr.cloud.samples.events

def result = get("/rest/api/2/issue/${issue.key}")
.header('Content-Type', 'application/json')
.asObject(Map)

def s = result.fields.assignee
if(s != null){

put("/rest/api/2/issue/
${issue.key}")
.header("Content-Type", "application/json")
.body([
fields:[
customfield_11925 : s
]


])
.asString()

}
0 votes

This looks weird to me:

(targetFieldName): sourceField.key

You are setting the "key" of the assignee field (not its value) to the  #14047 custom field?

I think this is the culprit. Check what is the body you are PUTting to the REST end-point.

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events