Depends upon the number of Component value’s the no. Tickets has to clone in destination project

Kumar
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.
December 16, 2019

Hello Team, 

 

I have a service desk project so on create transition I have added a scripted postfunction that to auto clone issues in 2 different destination projects. 
Here I need to apply a condition like If the JSD ticket components has 1 value then it has to clone one ticket in destination project 

 

If Component has 2 or 3 or 4 values it has to create those many tickets in the Destination projects 

 

can anyone please help with the scripted postfunction 

 

 

Thanks,

 

Phani

3 answers

1 accepted

0 votes
Answer accepted
Leo
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 19, 2019

Hi @Kumar,

I've written a custom script to clone issue depends on the size of components selected for the current issue

NOTE: this script clones no. of issues to single Target project for now, you need to modify script to clone in another project as well

 

import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import org.apache.log4j.Level
import org.apache.log4j.Logger

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def linkMgr = ComponentAccessor.getIssueLinkManager()
def issueManager = ComponentAccessor.getIssueManager()
def searchService = ComponentAccessor.getComponent(SearchService)
def issueFactory = ComponentAccessor.getIssueFactory()

def PROJECT_KEY_TO = "TARGET" // Target Project key
def projectTo = ComponentAccessor.getProjectManager().getProjectByCurrentKey(PROJECT_KEY_TO)
def comp = issue.getComponents() as List

for(int i = 0; i< comp.size(); i++){
def newIssue = issueFactory.cloneIssue(issue)
newIssue.setProjectObject(projectTo)
Map<String,Object> newIssueParams = ["issue":newIssue] as Map<String,Object>
issueManager.createIssueObject(currentUser, newIssueParams)
linkMgr.createIssueLink(newIssue.id, issue.id, 10001, 1, currentUser) // Here 10001 is my server's Clone link type ID. check in your server & replace it with valid id
log.info("Issue ${newIssue?.key} cloned to project ${projectTo.key}")
}

 

 

BR,

Leo 

Kumar
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.
December 23, 2019

Hello @Leo   

Thanks for your script it’s working as I expected a small correction to avoid static error

linkMgr.createIssueLink(newIssue.id, issue.id, 10001 as Long, 1 as Long, currentUser)

 

and once again thanks for your script.

 

 

Thanks,

Phani

0 votes
Leonard Chew
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.
December 17, 2019

If I get you right, you are using the default clone issue postfunction provided by scriptrunner, which can only clone one issue.

If you know all available Components, you could add one postfunction for each component with the condition:

def components = issue.components.toList()
components?.name.contains('MyComponent')

The better solution would be to write a custom-script that loops over all components and clones the issue for each component. 

I dont have a working script for that but found this:

https://mraddon.blog/2015/09/22/postfunction-groovy-script-runner-to-clone-issue-with-different-type-and-link-between/

Kumar
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.
December 19, 2019

Hello @Leonard Chew 

Actually I can apply condition like 
if “some field” = “X” option the create a issue 

but here I need give like

component= “x && y && z”

It has to create a 3 tickets for that how can I give the condition to that 

can you please help me here with the script

 

 

Thanks,

Phani

0 votes
Damian Wodzinski
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.
December 16, 2019

Do you have any line of code?

Kumar
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.
December 17, 2019

Hello @Damian Wodzinski 

No didn’t have any Line of code.

i just used the I used the postfunction which is provided by ScriptRunner for autoclone 

 

 

thanks,

phani

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events