Hi, I've just migrated from scriptrunner server to scriptrunner cloud and am trying to re-write my script to add multiple components to an issue.
I've tried this:
issueInput.fields.components = [[name: 'Operations1']]
which works and just sets a single component.
But when I try this:
issueInput.fields.components += [[name: 'Operations1']]
issueInput.fields.components += [[name: 'Operations2']]
I get the following error:
2019-04-16 10:25:42.463 ERROR - Cannot execute null+[{name=Operations1}] on line 1
2019-04-16 10:25:42.503 ERROR - Class: com.adaptavist.sr.cloud.workflow.UpdateIssue, Config: [className:com.adaptavist.sr.cloud.workflow.UpdateIssue, uuid:3f47bc8a-64d6-4100-840b-77be047f1861, description:Add Operations1 and Operations2 as Components, enabled:true, executionUser:ADD_ON, additionalCode:issueInput.fields.components += [[name: 'Operations1']]
issueInput.fields.components += [[name: 'Operations2']], userKey:e01807, accountId:5cb5998a9a857910896fd759]
Any ideas how I can get this to work please? I need the script to add the new components and leaving alone any existing components already attached to the issue. i.e. I do not want to overwrite what is there already - I need the new ones to be added.
Hi @E01807 ,
Below work for me:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.project.component.ProjectComponent
def projectComponentManager = ComponentAccessor.getProjectComponentManager()
def coll = projectComponentManager.findByComponentNameCaseInSensitive('A')
coll.addAll(projectComponentManager.findByComponentNameCaseInSensitive('B'))
issue.setComponent(coll)
More You might read here https://community.atlassian.com/t5/Jira-Core-questions/Script-runner-for-setting-up-a-component-based-on-issue-type/qaq-p/841359
That script is for Scriptrunner server version - not the cloud version. I'm using the cloud version. Your script gets the following errors on cloud:
2019-04-16 20:02:30.267 ERROR - startup failed: Script1.groovy: 2: unable to resolve class com.atlassian.jira.issue.MutableIssue @ line 2, column 1. import com.atlassian.jira.issue.MutableIssue ^ Script1.groovy: 4: unable to resolve class com.atlassian.jira.bc.project.component.ProjectComponent @ line 4, column 1. import com.atlassian.jira.bc.project.component.ProjectComponent ^ Script1.groovy: 3: unable to resolve class com.atlassian.jira.component.ComponentAccessor @ line 3, column 1. import com.atlassian.jira.component.ComponentAccessor ^ 3 errors
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @E01807 ,
You said that works below:
issueInput.fields.components = [[name: 'Operations1']]
Could You please check next:
def array = issueInput.fields.components.clone()
List clone=[]
array.each{
clone.add(it)
}
clone.add([name: 'Operations1'])
issueInput.fields.components = clone.toArray()
B.R.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It mean issueInput.fields.components is List. Therefore should work
issueInput.fields.components.add([name: 'Operations1'])
Have you checked this option?
B.R.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Just using that one line (twice, once for each component) didn't cause any static errors but gave me:
2019-04-17 15:03:06.502 ERROR - Cannot invoke method add() on null object on line 1
2019-04-17 15:03:06.602 ERROR - Class: com.adaptavist.sr.cloud.workflow.UpdateIssue, Config: [className:com.adaptavist.sr.cloud.workflow.UpdateIssue, uuid:3f47bc8a-64d6-4100-840b-77be047f1861, description:Add Operations1 and Operations2 as Components, enabled:true, executionUser:ADD_ON, additionalCode:issueInput.fields.components.add([name: 'Operations2'])
issueInput.fields.components.add([name: 'Operations1']), userKey:e01807, accountId:5cb5998a9a857910896fd759]
on execution
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @E01807 ,
Sorry for long time response. Was a lots job :-)
I reactivate my cloud jira and found resolution.
Both below work for me:
issueInput.update.components = [[add: [name:"A"]],[add: [name:"B"]]]
Or:
List comps = []
comps.add([add: [name:"A"]])
comps.add([add: [name:"B"]])
issueInput.update.components = comps
Other possible commands:
Supported operation(s) are: 'add,set,remove'
B.R.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry for the long delay - been busy! Your first suggestion worked a treat! Thank you so much for your help!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @E01807 ,
Not sure, but I suppose You need do it that:
def array = []
array.add([name: 'A'])
array.add([name: 'B'])
...
issueInput.fields.components = array
Or
issueInput.fields.components.add([name: 'A'])
I will check on my Jira and will write.
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.