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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,558,636
Community Members
 
Community Events
184
Community Groups

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

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

0 votes
Answer accepted

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.
Nov 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.
Nov 20, 2018

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

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.
Nov 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...

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events