Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Scriptrunner: How do i set component when cloning an issue in jira cloud?

Randy
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.
May 18, 2018

I'm trying to use scriptrunner's clone issue post function.  Since the destination project has component as a required field, I need to set the component.  

I have the component ID and am okay with hardcoding it in the script.  Anyone know how i would accomplish this?

 

I've tried the following so far:

issueInput.fields.components += {id: "12345"}

issueInput.fields.components = [id: "12345"]

 

Both result in the following error:

2018-05-18 21:37:56.342 ERROR - Infinite recursion (StackOverflowError) (through reference chain: java.util.LinkedHashMap["fields"]->java.util.LinkedHashMap["components"]->java.util.ArrayList[0]->_run_closure1["delegate"]->Script1["binding"]->groovy.lang.Binding["variables"]->java.util.LinkedHashMap["issueInput"]->java.util.LinkedHashMap["fields"]->java.util.LinkedHashMap["components"]->java.util.ArrayList[0]->_run_closure1["delegate"]->Script1["binding"]->groovy.lang.Binding["variables"]->java.util.LinkedHashMap["issueInput"]->java.util.LinkedHashMap["fields"]->java.util.LinkedHashMap["components"]->java.util.ArrayList[0]->_run_closure1["delegate"]->Script1["binding"]->groovy.lang.Binding["variables"]->java.util.LinkedHashMap["issueInput"]->java.util.LinkedHashMap["fields"]->java.util.LinkedHashMap["components"]->java.util.ArrayList[0]->_run_closure1["delegate"]->Script1["binding"]->groovy.lang.Binding["variables"]->java.util.LinkedHashMap["issueInput"]->java.util.LinkedHashMap["fields"]->java.util.LinkedHashMap["components"]->java.util.ArrayList[0]->_run_closure1["delegate"]->Script1["binding"]->groovy.lang.Binding["variables"]->java.util.LinkedHashMap["issueInput"]->java.util.LinkedHashMap["fields"]->java.util.LinkedHashMap["components"]->java.util.ArrayList[0]->_run_closure1["delegate"]->Script1["binding"]->groovy.lang.Binding["variables"]->java.util.LinkedHashMap["issueInput"]->java.util.LinkedHashMap["fields"]->java.util.LinkedHashMap["components"]->java.util.ArrayList[0]->_run_closure1["delegate"]->Script1["binding"]->groovy.lang.Binding["variables"]->java.util.LinkedHashMap["issueInput"]->java.util.LinkedHashMap["fields"]->java.util.LinkedHashMap["components"]->java.util.ArrayList[0]->_run_closure1["delegate"]->Script1["binding"]->groovy.lang.Binding["variables"]->java.util.LinkedHashMap["issueInput"]->java.util.LinkedHashMap["fields"]->java.util.LinkedHashMap["components"]->java.util.ArrayList[0]->_run_closure1["delegate"]->Script1["binding"]->groovy.lang.Binding["variables"]->java.util.L
2018-05-18 21:37:56.502 ERROR - Class: com.adaptavist.sr.cloud.workflow.CloneIssue, Config: [className:com.adaptavist.sr.cloud.workflow.CloneIssue, uuid:redacted, description:Clones to Project, enabled:true, condition:, issueTypeId:, projectId:1234, executionUser:INITIATING_USER, linkTypeId:10001, linkDirection:Inward, 

It looks like it's running into an infinite loop when serializing the component field?  Is this a bug or am I missing something?

1 answer

1 accepted

2 votes
Answer accepted
Kristian Walker _Adaptavist_
Community Champion
May 21, 2018

Hi Randy,

The components field is an array so to set the value you require, you should use syntax similar to the example show below where you specify the component by its name using a name, value pair.

issueInput.fields.components = [[name: '<ComponentNameHere>']]

If this answer has solved your issue can you please accept it in order to mark this answer as correct for users who are searching for a similar issue.

Regards,

Kristian

Randy
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.
May 21, 2018

That did it.  Thanks!

E01807 April 17, 2019

Any idea how you do this so that you can add a new component without overwriting any components that are already there? I have a use case where I want to be able to add multiple components either through scripts or by the users.

Randy
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.
April 17, 2019

@E01807  you can read from the components field, add to the array, then set the array to the issueInput component field as Kristian showed above.

E01807 April 23, 2019

Thanks @Randy . I'm pretty new to this. Would it be possible for you to post a code snippet on how this might be achieved?

Randy
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.
April 23, 2019

This might work.  Note that it's untested.  Assumes Issue and issueInput are available in the script context as bindings

 

def newComponentList = issue.fields.components.clone()

newComponentList.add([name: 'New Component'])

issueInput.fields.components = newComponentList

Suggest an answer

Log in or Sign up to answer