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
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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"])
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks, .asObject(Map) was the piece I was missing.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@[deleted] can you pass me the example you used to get the value of a field ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.