clone an issue with all sub tasks

Hi,
Usually, I create a swim lane with 4 or 5 subtasks related to issue. From the issues page if I select the feature with all subtasks and try to clone them all the subtasks are getting created as subtasks of the original swim lane. Is there a way to clone a swim lane with its subtasks as one set or any other way to copy them as a I set.
thanks,
VK
0
12 comments
Hi VK,

Unfortunately, it's not possible at the moment. I guess it can be implemented in future as an additional option, like 'Clone Tree' or similar.

Thank you for your suggestion!
0
Thank you for the reply! i will look for it in the future versions :)
0

Hi! Has the situation changed? I'd also find cloning a template issue tree useful.

0

Hi! 

No, it has not changed, I'm afraid. Here's the related feature request: https://youtrack.jetbrains.com/issue/JT-34291 So far, it's not gotten much attention (votes), though it's not the only factor, it still matters. Feel free to vote for it, as it increases its priority and subscribes you to the email notifications. To do so, sign in to Jetbrains Youtrack: https://take.ms/41YJh (screenshot) 

0

I'm new to YouTrack and immediately ran into this issue as well.  

I created a custom workflow implementation that does this.  See https://youtrack.jetbrains.com/issue/JT-34291 for details.  My implementation is recursive, so it'll clone a whole tree of subtasks, plus it'll add "(Clone)" to the summary of the top-level issue.

The only thing I didn't created as a "cloned" link (like you might have in JIRA).  I haven't learned how to detect whether or not a certain link type exists or not, but if I did, I'd check to see if "Cloned" exists and if so, then add a link for the top-level parent.

0

Hi Trev, you can use `IssueLinkPrototype.findByName(name)` method as described here 

0

Cool Anna Zhdan, thanks for the pointer.   I tried using that, but kept getting an error and I'm not sure what I did wrong.

I created a link type called "Clone" with outward name = "cloned to" and inward name = "cloned from".

Then I added the following logic to my workflow:

// Add cloned link if Clone link types exist

if (workflow.IssueLinkPrototype.findByName('cloned to') !== null) {
issue.links['cloned to'].add(newIssue);
}
When I tried using my subtask w/clone workflow, it generates a "bad_request" error.  The error isn't very clear about exactly what's wrong.  I tried a few variations of this using findByName('Clone') and issue.links['clone'].
0

Here's the full workflow I was trying in case that helps:

var entities = require('@jetbrains/youtrack-scripting-api/entities');
var workflow = require('@jetbrains/youtrack-scripting-api/workflow');

exports.rule = entities.Issue.action({
  title: workflow.i18n('Clone (w/Subtasks)'),
  command: 'clone-with-subtasks',
  guard: function(ctx) {
    return ctx.issue.isReported;
  },
  action: function(ctx) {
    var issue = ctx.issue;
    
    var newIssue = issue.copy();
    newIssue.summary += ' (Clone)';
    
    var copySubtask = function(newParent, subtask) {
      var newSubtask = subtask.copy();
      newParent.links['parent for'].add(newSubtask);

      // Recurse
      subtask.links['parent for'].forEach(function (subtask) { return copySubtask(newSubtask, subtask); });
    };
    
    // Copy subtasks
    issue.links['parent for'].forEach(function (subtask) { return copySubtask(newIssue, subtask); });
    
    // Add cloned link if Clone link types exist
    if (workflow.IssueLinkPrototype.findByName('cloned to') !== null) {
issue.links['cloned to'].add(newIssue);
    }
    
    workflow.message(workflow.i18n('A clone of the current issue has been created: <a href="{0}">{1}</a>', newIssue.url, newIssue.id));
  },
  requirements: {
    // TODO: add requirements
  }
});

 

0

Trev could you please attach logs of this workflow rule? They can be found in the lower panel in workflow editing UI. Could you please also attach a screenshot of your Issue Links Settings page?

 

0

Anna Zhdan, ah, I didn't see the workflow console.  That's useful.  The message I got there is pretty clear:

Processing issue SALT-4:
TypeError: Cannot read property 'findByName' of undefined

I could attack the stack trace, but we probably don't need it, we already know exactly where that's happening.  

Strange that it's not finding IssueLinkPrototype because the editor found that it was available via workflow.  I'm still a little new to javascript, so maybe I'm missing an important piece of syntax that's not obvious.

Here's a screen shot of my Issue Link Types settings page:

 

0

Trev

I'm sorry I didn't notice it before: it should be

entities.IssueLinkPrototype

instead of 

workflow.IssueLinkPrototype
0

That did the trick, thanks!   I had to make one other tweak, which was to refer to the clone link type in the look up and refer to the outgoing link name in the adding of the link.  All works now, thanks!

    // Add cloned link if Clone link types exist
    if (entities.IssueLinkPrototype.findByName('Clone') !== null) {
issue.links['cloned to'].add(newIssue);
    }

 

0

Please sign in to leave a comment.