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,555,973
Community Members
 
Community Events
184
Community Groups

Create a clone issue when a new issue was created

Edited

@Thanos Batagiannis [Adaptavist]

I did run script below, but looks like no clone issue was created.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.link.IssueLinkTypeManager
import com.onresolve.scriptrunner.canned.jira.utils.ConditionUtils
import com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CloneIssue

def issue = issue as MutableIssue

def customFieldManager = ComponentAccessor.getComponent(CustomFieldManager)
def customField = customFieldManager.getCustomFieldObjectByName("SelectListA")
def cfValue = customField.getValue(issue)

def targetProjectKeyA = "JRA"
def blocksId = ComponentAccessor.getComponent(IssueLinkTypeManager).getIssueLinkTypes().findByName("Blocks")?.id

def inputs = [
    issue                                   : issue,
    (CloneIssue.FIELD_LINK_TYPE)            : blocksId,
    (ConditionUtils.FIELD_ADDITIONAL_SCRIPT): """issue.setSummary('my summary')""",
    (CloneIssue.FIELD_SELECTED_FIELDS)      : null, //clone all the fields    
(CloneIssue.SKIP_EPIC_LINKS) : "true",
(CloneIssue.FIELD_USER_KEY) : "admin",
] as Map<String, Object> log.debug "Value of custom field is ${cfValue}" if (cfValue?.toString() == "AAA") { inputs.put((CloneIssue.FIELD_TARGET_PROJECT), targetProjectKeyA) new CloneIssue().doScript(inputs) }

 

1 answer

1 accepted

0 votes
Answer accepted
Thanos Batagiannis [Adaptavist]
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 01, 2017

Hey Q, 

Did you change the names to match your's ? 

Also this should be a post function in the create issue transition, after the Issue Created step. 

One last thing, did you check your logs for any errors ?

regards, Thanos

@Thanos Batagiannis [Adaptavist]

 

Yes it works. Thanks, Will this contain clone and link operation?And , I would like to change from block to 'is caused by' what is the keyword I should use?

Yes it works. Thanks

Thanos Batagiannis [Adaptavist]
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 03, 2017

Glad to hear that Q, could you please accept the answer so others may benefit from it ?

Regards, Thanos

@Thanos Batagiannis [Adaptavist]

Could you share with me other issue link type keywords?

Thanos Batagiannis [Adaptavist]
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 03, 2017

Hey Q,

You can navigate to the Issue Types section in your jira, or you can use the following script in your script console and get the list 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLinkTypeManager

ComponentAccessor.getComponent(IssueLinkTypeManager).getIssueLinkTypes().collect {
"Name: ${it.name} | Inward name: ${it.inward} | Outward Name: ${it.outward}"
}.join("<br>")

Regards, Thanos

@Thanos Batagiannis [Adaptavist]

Is there anyway I can add 'As user' The user that will run as, like the function we have in the clone,link buildin function?

Thanos Batagiannis [Adaptavist]
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 03, 2017

I edited your script, adding the "as User" field.

@Thanos Batagiannis [Adaptavist]

 

I hit errors as below:

2017-11-03 13:09:16,575 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2017-11-03 13:09:16,575 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: EC-26, actionId: 1, file: <inline script>
com.atlassian.jira.exception.CreateException: Cannot retrieve configured user abc for cloning issue. Reconfigure function.
 at com.onresolve.scriptrunner.canned.jira.utils.AbstractCloneIssue.doScript(AbstractCloneIssue.groovy:131)
 at com.onresolve.scriptrunner.canned.jira.utils.CopyIssueWithAttachments.super$2$doScript(CopyIssueWithAttachments.groovy)
 at com.onresolve.scriptrunner.canned.jira.utils.CopyIssueWithAttachments.doScript(CopyIssueWithAttachments.groovy:13)
 at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CloneIssue.super$3$doScript(CloneIssue.groovy)
 at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CloneIssue.doScript(CloneIssue.groovy:102)
 at com.onresolve.scriptrunner.canned.CannedScript$doScript.call(Unknown Source)
 at Script401.run(Script401.groovy:31)

user abc is a admin user

Thanos Batagiannis [Adaptavist]
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 03, 2017

Is "abc" his user key ?

@Thanos Batagiannis [Adaptavist]

abc is userID, how to get user key?

Thanos Batagiannis [Adaptavist]
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 03, 2017

try the script below in your script console 

import com.atlassian.jira.component.ComponentAccessor

ComponentAccessor.getUserManager().getUserByName("abc")?.key

@Thanos Batagiannis [Adaptavist]

2017-11-03 13:12:29,663 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2017-11-03 13:12:29,663 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: EC-28, actionId: 1, file: <inline script>
com.atlassian.jira.exception.CreateException: Cannot retrieve configured user ABC for cloning issue. Reconfigure function.
 at com.onresolve.scriptrunner.canned.jira.utils.AbstractCloneIssue.doScript(AbstractCloneIssue.groovy:131)
 at com.onresolve.scriptrunner.canned.jira.utils.CopyIssueWithAttachments.super$2$doScript(CopyIssueWithAttachments.groovy)
 at com.onresolve.scriptrunner.canned.jira.utils.CopyIssueWithAttachments.doScript(CopyIssueWithAttachments.groovy:13)
 at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CloneIssue.super$3$doScript(CloneIssue.groovy)
 at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CloneIssue.doScript(CloneIssue.groovy:102)
 at com.onresolve.scriptrunner.canned.CannedScript$doScript.call(Unknown Source)
 at Script404.run(Script404.groovy:31)

 

Replaced with user key, got error above.

Correction, it work, looks like after original issue was create, clone and link will take some time.

Thanos Batagiannis [Adaptavist]
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 03, 2017

Probably the 

def blocksId = ComponentAccessor.getComponent(IssueLinkTypeManager).getIssueLinkTypes().findByName("Blocks")?.id

does not exist (returns null) therefore does not create any link.

@Thanos Batagiannis [Adaptavist]

Looks like sometimes it show as current user created the clone issue, sometimes 'As user' create clone issue. Any suggestions?

Hi @Qi Jiang

 

I was looking at your post and I was wondering how you figured the properties for 

 

(CloneIssue.FIELD_LINK_TYPE)
(ConditionUtils.FIELD_ADDITIONAL_SCRIPT)
(CloneIssue.FIELD_SELECTED_FIELDS)
(CloneIssue.SKIP_EPIC_LINKS)
(CloneIssue.FIELD_USER_KEY)

I'm trying to find the property for PARENT and I can't find documentation anywhere.
I would appreciate it if you could help me find it.

Thanks! 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events