Insert new items into a custom Select List with REST/Scriptrunner

Deleted user January 4, 2017

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

 

1 answer

1 accepted

4 votes
Answer accepted
Jon Bevan [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 4, 2017

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

Jon Bevan [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 4, 2017

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.

Deleted user January 4, 2017

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

Jon Bevan [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 4, 2017

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.

Deleted user January 4, 2017

Yes it seems odd. I'll see what I can figure out with a script. Thank you for your time.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events