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,359,951
Community Members
 
Community Events
168
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 

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.

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

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
Community showcase
Published in Jira

Online AMA this week: Your project management questions answered by Jira Design Lead James Rotanson

We know that great teams require amazing project management chops. It's no surprise that great teams who use Jira have strong project managers, effective workflows, and secrets that bring planning ...

179 views 1 6
Read article

Atlassian Community Events