Hi,
I'm running JIRA Cloud
I've been looking for an easy way to insert many items into a Select List without doing it manually.
It seems I should use the REST API commands:
https://docs.atlassian.com/jira/REST/cloud/#api/2/field/{fieldKey}/option
But I've been unable to get it to work using ScriptRunner. I've tried the following command:
get('/rest/api/2/field/customfield_10947/option')
And I get the following result
undefined 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)
And logs
2017-01-04 15:00:42,847 ERROR - Failed to serialise output 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)
I haven't used REST much so there might be something simple I'm missing here like how to convert the data to something readable once received or how to structure the arguments on PUT calls. If there is another way of doing this I would love to know.
For the PUT I believe I'll have to use:
PUT /rest/api/2/field/{fieldKey}/option/{optionId}
Any information you can give me will be greatly appreciated.
Kind regards
Thomas P. Hargreaves
Hi Thomas,
Sadly Atlassian haven't provided a REST API for doing what you're looking for here.
The documentation you linked to specifies that those endpoints only work for Issue Fields as opposed to Custom Fields.
Thanks, Jon
Additionally, your code snippet won't work unless you call .asObject() or .asString() on the return value of the get() method call:
E.g.
get('/rest/api/2/issuetype').asString().body
See http://scriptrunner-docs.connect.adaptavist.com/jiracloud/ for more examples.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you Jon,
Do you know of any other way I might be able to do this. It seems unlikely that noone else might have wanted this feature?
Kind regards
Thomas P. Hargreaves
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The only other way I can think of doing this is to script some kind of browser session that uses the endpoints that the UI uses.
This is a closed ticket for the feature request from Atlassian: https://ecosystem.atlassian.net/browse/ACJIRA-177
I don't understand why they have no intention of developing a REST API for this.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes it seems odd. I'll see what I can figure out with a script. Thank you for your time.
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.