Need to mofify code below so I can apply to a list / array of projectname...
Would also like to copy over custom fields - I have some of that code, but missing something:
for (CustomField cf : customFieldManager.getCustomFieldObjects(issue)) { if (issue.getCustomFieldValue(cf)) { newissue.setCustomFieldValue(cf, oneIssue.getCustomFieldValue(cf)) } }
Ref:
Current / Working code:
______________________________________
import com.atlassian.core.user.UserUtils import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.link.IssueLink import com.atlassian.jira.util.ImportUtils import com.opensymphony.user.User import com.opensymphony.workflow.WorkflowContext import org.apache.log4j.Category log = Category.getInstance("com.onresolve.jira.groovy.CreateDependentIssue") // Configurable section def projectName = "PMO-Test" // Name of project you want to create the issue in // for other customisations change the code below issueMgr = ComponentManager.getInstance().getIssueManager() projectMgr = ComponentManager.getInstance().getProjectManager() String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller(); User currentUserObj = UserUtils.getUser(currentUser); def wasIndexing = ImportUtils.indexIssues ImportUtils.indexIssues = true issueFactory = ComponentManager.getInstance().getIssueFactory() newissue = issueFactory.getIssue() newissue.setSummary ("Tier I Common - $issue.summary") newissue.setProject (projectMgr.getProjectByName(projectName)) newissue.setIssueType (issue.getIssueType()) newissue.description = issue.description newissue.reporter = issue.getReporter() params = ["issue":newissue] subTask = issueMgr.createIssue(currentUserObj, params) println subTask.get("key") // get the current list of outwards depends on links to get the sequence number linkMgr = ComponentManager.getInstance().getIssueLinkManager() def sequence = 0 for (IssueLink link in linkMgr.getInwardLinks(issue.id)) { if ("Depends" == link.issueLinkType.name) { sequence++; } } linkMgr = ComponentManager.getInstance().getIssueLinkManager() // TODO: Should check that 10002 is always the link id for Depends linkMgr.createIssueLink (newissue.id, issue.id, 10001, sequence, currentUserObj) ImportUtils.indexIssues = wasIndexing
Community moderators have prevented the ability to post new answers.
Moved here - ran out of room... :(
Does it not work? I can't really see what the question is ;-)
Custom fields I do like this:
newIssueCfs.intersect(customFieldManager.getCustomFieldObjects(issue)).each {CustomField cf ->
Probably better written:
ProjectList.each() {projectName
....
projectMgr.getProjectByName(projectName)
Try to avoid "it" in long loops, gets a bit confusing. Otherwise looks ok at first glance.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Deborah,
I have done something very similar. Your custom field copy code is correct - I am using the exact same code. I wonder if your issue is caused by the placement of that code. I have it above the issue creation.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here is my linking code - this bypasses the 10002 concern
Collection cloneIssueLinkTypes = issueLinkTypeManager.getIssueLinkTypesByName("Cloners") for (Iterator iterator = cloneIssueLinkTypes.iterator(); iterator.hasNext();) { IssueLinkType issueLinkType = (IssueLinkType) iterator.next(); if (issueLinkType.getName() == "Cloners" ) { cloneIssueLinkType = issueLinkType.getId(); } } linkMgr.createIssueLink (issue.id, newissue.id, cloneIssueLinkType, sequence, currentUserObj)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
P.S> I notice you use "newissue = issueFactory.getIssue()"
I use "newissue = issueFactory.cloneIssue(issue)"
This means that it automatically sets the reporter, description etc on creation (although you can override it). It makes for a bit less work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you Jon! I think I'm running inot havoc because I have the for statement inside an project list array - a sub-loop in my loop.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have the project array functioning - - custom fields pending...
import com.atlassian.core.user.UserUtils import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.link.IssueLink import com.atlassian.jira.util.ImportUtils import com.opensymphony.user.User import com.opensymphony.workflow.WorkflowContext import org.apache.log4j.Category log = Category.getInstance("com.onresolve.jira.groovy.CreateDependentIssue") // Configurable section def ProjectList = ["Project A", "Project B"] //list of projects ProjectList.each() { // for other customisations change the code below issueMgr = ComponentManager.getInstance().getIssueManager() projectMgr = ComponentManager.getInstance().getProjectManager() String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller(); User currentUserObj = UserUtils.getUser(currentUser); def wasIndexing = ImportUtils.indexIssues ImportUtils.indexIssues = true issueFactory = ComponentManager.getInstance().getIssueFactory() newissue = issueFactory.getIssue() newissue.setSummary ("Common - $issue.summary") newissue.setProject (projectMgr.getProjectByName("${it}")) newissue.setIssueType (issue.getIssueType()) newissue.description = issue.description newissue.reporter = issue.getReporter() params = ["issue":newissue] subTask = issueMgr.createIssue(currentUserObj, params) println subTask.get("key") // get the current list of outwards depends on links to get the sequence number linkMgr = ComponentManager.getInstance().getIssueLinkManager() def sequence = 0 for (IssueLink link in linkMgr.getInwardLinks(issue.id)) { if ("Depends" == link.issueLinkType.name) { sequence++; } } linkMgr = ComponentManager.getInstance().getIssueLinkManager() // TODO: Should check that 10002 is always the link id for Depends linkMgr.createIssueLink (newissue.id, issue.id, 10001, sequence, currentUserObj) ImportUtils.indexIssues = wasIndexing }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.