How can i set a Collection Filed while cloning via ScriptRunner

Martin Schmalz July 19, 2018

hey,

im trying to make a new issue out of a workflow-transaction via scriptrunner -> clone an issue an link. atm - it works perfect.

but i want to add some more fields to the new issue.

i can define the summary (issue.summary) and i can fill the description.

but i have problems with issue.components (and issue.versions). i get errors trying

issue.components = "Component 1" -> cannot cast string to collection

issue.components = "1" -> cannot cast integer to collection

 

i see the problem - but whats the right way to fill the collection?

*thx*

2 answers

0 votes
Alexey Matveev
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.
July 19, 2018

Hello,

Try like this:

import com.atlassian.jira.component.ComponentAccessor

def component = ComponentAccessor.getProjectComponentManager().findByComponentName(issue.getProjectId(), "Component 1")
issue.setComponent([component])
Martin Schmalz July 20, 2018

Hey, another error

groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.IssueImpl.setComponent() is applicable for argument types: (java.util.ArrayList)

 

when i try setComponents[component] - i get the same error i got after Marks answer

com.atlassian.jira.bc.project.component.ProjectComponentImpl cannot be cast to org.ofbiz.core.entity.GenericValue

Alexey Matveev
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.
July 20, 2018

Kindly make changes to the script like this

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption


def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def missue = ComponentAccessor.getIssueManager().getIssueObject(issue.getKey())
def component = ComponentAccessor.getProjectComponentManager().findByComponentName(missue.getProjectId(), "Component 1")
issue.setComponent([component])
ComponentAccessor.getIssueManager().updateIssue(user, missue, EventDispatchOption.ISSUE_UPDATED, false)
Martin Schmalz July 20, 2018

Cannot invoke method getProjectId() on null object

0 votes
Mark Markov
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.
July 19, 2018

Hello @Martin Schmalz

Try

issue.components = ["Component 1" ]

Martin Schmalz July 19, 2018

Hey,

now the error is

java.lang.String cannot be cast to org.ofbiz.core.entity.GenericValue

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events