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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

2 votes
Answer accepted

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"])

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.

@Kris Scott  can you pass me the example you used to get the value of a field ?

I am also looking for information on how to get subtasks as objects. 

Using this example:

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

I would expect that I could use:

def subtasks = currentIssue.fields.subtasks

but that gives me an error: No such property subtasks...

Tamsin I'm New Here Oct 28, 2020

I had the same problem, until I realised that all the data is inside the body element.

So this should work:

def subtasks = currentIssue.body.fields.subtasks

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you