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

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

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.

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

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.

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 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,316 views 14 20
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