Create a clone issue when a new issue was created

Qi Jiang November 1, 2017

@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

Suggest an answer

Log in or Sign up to answer
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.
November 1, 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

Qi Jiang November 3, 2017

@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?

Qi Jiang November 3, 2017

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.
November 3, 2017

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

Regards, Thanos

Qi Jiang November 3, 2017

@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.
November 3, 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

Qi Jiang November 3, 2017

Thanks

Qi Jiang November 3, 2017

@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.
November 3, 2017

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

Qi Jiang November 3, 2017

@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.
November 3, 2017

Is "abc" his user key ?

Qi Jiang November 3, 2017

@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.
November 3, 2017

try the script below in your script console 

import com.atlassian.jira.component.ComponentAccessor

ComponentAccessor.getUserManager().getUserByName("abc")?.key
Qi Jiang November 3, 2017

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

Qi Jiang November 3, 2017

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.
November 3, 2017

Probably the 

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

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

Qi Jiang November 3, 2017

@Thanos Batagiannis _Adaptavist_

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

YAVUZ AKIN May 27, 2020

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! 

TAGS
AUG Leaders

Atlassian Community Events