How to get a specific issue object by id in Script Runner for Jira Cloud Edited

I am attempting to troubleshoot a script runner workflow post function in the script runner console, and would like to assign the default issue object to a specific issue by id so I can use the console to run and edit the failing code.

How can I assign the issue object to a specific issue by ID? I would expect something like:

     def issue = getIssueByID("JRA-123")

so that I can then do stuff like:

     def fieldValue = issue.fields[fieldID] as String

1 answer

1 accepted

1 vote
Jenna Davis Community Champion Jan 08, 2018

Hello, 

You can use the IssueManager from JIRA's API to do this. I believe specifically that getIssueObject('your Issue ID') will do what you are looking for. 

You'll also probably want to take a look at Issue and MutableIssue for information on how to get and set values in an issue. 

Hope this helps you out!
Jenna

Hi Jenna,

Thanks for responding. All of that makes sense, I just can't seem to figure out how to make that kind of call using the REST APIs since I'm in the cloud environment and can't use the Java API. 

It seems like maybe it should be as simple as:

     def issue = get('/rest/api/2/issue/JRA-123')

but that throws the following error, so I imagine I need to explicitly map it maybe?

com.fasterxml.jackson.databind.JsonMappingException: Direct self-reference leading to cycle (through reference chain: com.adaptavist.sr.cloud.output.ScriptExecutionOutput["result"]->groovy.util.Proxy["adaptee"]->com.mashape.unirest.request.GetRequest["httpRequest"])
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter._handleSelfReference(BeanPropertyWriter.java:781)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:569)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:666)
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:156)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:575)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:666)
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:156)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:575)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:666)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeWithType(BeanSerializerBase.java:552)
at com.fasterxml.jackson.databind.ser.impl.TypeWrappedSerializer.serialize(TypeWrappedSerializer.java:32)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:129)
at com.fasterxml.jackson.databind.ObjectWriter._configAndWriteValue(ObjectWriter.java:1052)
at com.fasterxml.jackson.databind.ObjectWriter.writeValueAsString(ObjectWriter.java:923)
at com.fasterxml.jackson.databind.ObjectWriter$writeValueAsString.call(Unknown Source)
at com.fasterxml.jackson.databind.ObjectWriter$writeValueAsString.call(Unknown Source)

Hi Jenna,

Thanks for responding. All of that makes sense, I just can't seem to figure out how to make that kind of call using the REST APIs since I'm in the cloud environment and can't use the Java API. 

It seems like maybe it should be as simple as:

     def issue = get('/rest/api/2/issue/JRA-123')

but that throws the following error, so I imagine I need to explicitly map it maybe?

com.fasterxml.jackson.databind.JsonMappingException: Direct self-reference leading to cycle (through reference chain: com.adaptavist.sr.cloud.output.ScriptExecutionOutput["result"]->groovy.util.Proxy["adaptee"]->com.mashape.unirest.request.GetRequest["httpRequest"])
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter._handleSelfReference(BeanPropertyWriter.java:781)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:569)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:666)
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:156)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:575)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:666)
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:156)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:575)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:666)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeWithType(BeanSerializerBase.java:552)
at com.fasterxml.jackson.databind.ser.impl.TypeWrappedSerializer.serialize(TypeWrappedSerializer.java:32)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:129)
at com.fasterxml.jackson.databind.ObjectWriter._configAndWriteValue(ObjectWriter.java:1052)
at com.fasterxml.jackson.databind.ObjectWriter.writeValueAsString(ObjectWriter.java:923)
at com.fasterxml.jackson.databind.ObjectWriter$writeValueAsString.call(Unknown Source)
at com.fasterxml.jackson.databind.ObjectWriter$writeValueAsString.call(Unknown Source)

Hi Jenna,

Thanks for responding. All of that makes sense, I just can't seem to figure out how to make that kind of call using the REST APIs since I'm in the cloud environment and can't use the Java API.

It seems like maybe it should be as simple as:

def issue = get('/rest/api/2/issue/JRA-123')

but that throws the following error, so I imagine I need to explicitly map it maybe?

com.fasterxml.jackson.databind.JsonMappingException: Direct self-reference leading to cycle (through reference chain: com.adaptavist.sr.cloud.output.ScriptExecutionOutput["result"]->groovy.util.Proxy["adaptee"]->com.mashape.unirest.request.GetRequest["httpRequest"])

Jenna Davis Community Champion Jan 08, 2018

Ahh, sorry. I completely missed that you were using cloud. You should be able to do something close to this:

def issueKey = "TEST-1"
def currentIssue = get('/rest/api/2/issue/' + issueKey)
        .asObject(Map)

 Here is some documentation that might help you out further also. :)

Jenna

Thanks, .asObject(Map) was the piece I was missing.

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,199 views 13 19
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
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