Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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?

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
Community showcase
Published in Marketplace Apps & Integrations

Staying organized with Jira: best practices for a better project management

Project managers know this problem: A “mountain of work” lays in front of you, and you don’t know how and where to tackle them. Different to-dos lie ahead, but just one task after the other can be ha...

176 views 2 1
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you