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

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

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?

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?

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

Is "abc" his user key ?

@Thanos Batagiannis [Adaptavist]

abc is userID, how to get user key?

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.

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?

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Fadoua M. Boualem
Published Monday in Trello

Using Trello to manage events

As a Jira power user, I was at first doubtful that Trello could benefit my workflow. Jira already uses boards (ones you can customize!), so why would I even need to use Trello?! In this post you will...

457 views 7 8
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you