Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to add multiple Component/s when using script post function to Clone issues.

Wayne Cranford November 20, 2018

The following sets a single component, but need to add up to 5 different Components on several of the issues cloned during a script post function.  I searched online and could not find any examples on how to accomplish.

def projectComponentManager10 = ComponentAccessor.getProjectComponentManager()
def newcomponent10= projectComponentManager10.findByComponentName(project10.getId(), "FSU")
 issue.setComponent([newcomponent10])

Environment - Adaptavist ScriptRunner v5.3.5 with JIRA v 7.4.4

 Thanks,

2 answers

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
Wayne Cranford January 17, 2019

Sorry for my delayed update - holiday, year-end vacation, cold, but found a solution that works as needed. Found that defining another selection was all that is needed. While the below example only shows cloning the issue with only 2 Component selection using a Post Function script, I have another with 6.

def projectComponentManager12 = ComponentAccessor.getProjectComponentManager()
def newcomponent12= projectComponentManager12.findByComponentName(project12.getId(), "DPU624VG")
def newcomponent121= projectComponentManager12.findByComponentName(project12.getId(), "DPU648VG")
issue.setComponent([newcomponent12,newcomponent121])

Thanks!
Wayne 

0 votes
Cristian Rosas [Tecnofor]
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.
November 20, 2018

Hi Wayne,

Use this:

def allComponent = issue.getComponent()
def newComponent = hereYourNewComponent

if (!allComponent .contains(newComponent)) {

    allComponent .addAll(newComponent)
    issue.setComponent(allComponent )

}

With this, you have a variable which has the old values of the component and, if the new component is not in that collection, then it adds the new component.

Cristian Rosas [Tecnofor]
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.
November 20, 2018

Oh, remember to put this post function before the issue update post function or you will need to use updateIssue

Wayne Cranford November 20, 2018

Cristian,

 

Thank you for the response, I did try to implement and ran into the "Cannot call <T>" error. I will work to see if I can resolve.

 

Wayne

 

image.png

Cristian Rosas [Tecnofor]
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.
November 20, 2018

newComponent is a String in that definition you made. You need to use the get component as you did in your script:

def projectComponentManager10 = ComponentAccessor.getProjectComponentManager()
def newcomponent10= projectComponentManager10.findByComponentName(project10.getId(), "FSU")

I recommend to use the Script Console first. In the console you will need a mutable issue as in this example:

import com.atlassian.jira.issue.MutableIssue

def issueManager = ComponentAccesor.getIssueManager()
def issue = issueManager.getIssueObject("XXX-000") as MutableIssue

You can also check logs in the console easier with logs:

log.warn whatYouWantToCheck

Anyway I see you are using the script in the "Aditional issue actions". I guess you are using the create subtasks psot function from scriptrunner. I personally don't like it and create the subtasks with a custom script because it works... weird...

Wayne Cranford November 20, 2018

Cristian,

 

Thank you for the additional direction, I will be able to try this on Monday, Nov 26, after vacation and holiday.

Yes - this is being used as Additional Issue Actions.  Our IT Department is short-staffed  and not able to support JIRA request. The script post function has served adequately, but this will be the biggest script work to date.  I am an engineering program manager, not a developer, so the hope is to get this operational and working and then we can get a software developer resource in the future to move to a custom script.  

Thanks again and will keep you posted

TAGS
AUG Leaders

Atlassian Community Events