move issue using script or web-item

NogaE September 19, 2016

Hi guys,

 

Does anyone has a working script/web-item&resource for JIRA 7.1.8 that moves an issue to a certain project?

 

Thanks,

Noga.

4 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
NogaE September 25, 2016

Taking it into consideration. Thank you smile

0 votes
Jonny Carter
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.
September 22, 2016

It certainly could create problems, though which ones are likely to manifest is hard to say. I believe the ProjectManager.getNextId method is transactional, so you shouldn't see problems where the same ID gets taken by multiple processes. I'm not 100% certain on that, though. If I'm right, and the script fails for some reason after grabbing the ID, you could potentially get gaps in your issue ID sequence.

Hard-coding the Issue Type Id and Status ID might lead to problems if you do some status re-naming/re-organizing, but then again, so could looking them up by their name.

I can't think of any other issues off the top of my head, though the more you run the script, the more likely you are to run into problems if they're there, right?

To quote a wise person, "The fact that this is not available in any @PublicApi should probably be enough to put you off, unless you have a taste for adventure." smile If it works, and you don't mind dealing with messes (such as broken issue key referals across multiple moves), and you don't need to lean too hard on it (i.e., if it stops working, you're not in trouble), then you're proooobably fine?

0 votes
NogaE September 22, 2016

Hi Jonny,

Thank you for your reply. Before you commented, I manage to write the following script who does the move as expected:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.IssueFactory
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.link.IssueLinkType
import com.atlassian.jira.issue.link.IssueLinkTypeManager
import com.atlassian.jira.issue.link.DefaultIssueLinkManager
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.issue.util.IssueChangeHolder
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.event.issue.IssueEvent
IssueEvent event;
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() 
def issueFactory =ComponentAccessor.getIssueFactory()
MutableIssue issue = ComponentAccessor.getIssueManager().getIssueObject("IS-3");
def projectManager = ComponentAccessor.getProjectManager();
def targetProject = projectManager.getProjectObjByKey("RB");
def nextId = projectManager.getNextId(targetProject);

issue.setProjectObject(targetProject);
issue.setNumber(nextId);
issue.setIssueTypeId('10001');
issue.setStatusId('10002');
issue.store();
def currentUser = ComponentAccessor.jiraAuthenticationContext?.getLoggedInUser()
ComponentAccessor.getIssueManager().updateIssue(currentUser, issue, EventDispatchOption.ISSUE_UPDATED, false);

Wanted to know if you think it is OK or going to create many problems?

 

Thanks,

Noga. 

0 votes
Jonny Carter
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.
September 21, 2016

This has been a difficult thing to do in JIRA for a while, almost deliberately so. See https://answers.atlassian.com/questions/150179 and https://jira.atlassian.com/browse/JRA-16494. Generally, Atlassian recommend you don't move issues around for any reason other than getting them to the right project after miscreation. If you're doing it often enough that you need to automate it (beyond using the Bulk Move option in the issue navigator), then you may be setting yourself up for hurt down the road.

Jamie's old gist at https://gist.github.com/jamieechlin/5213550 might be adaptable to the JIRA 7.1 context, but even if you ported it, the script is likely to break across upgrades, as Atlassian is deliberately keeping the the move operation out of the public API.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events