I am trying to pull a list of issues by custom field and convert them to sub tasks with a specified parent.
I have verified my JQL query is being constructed correctly and retrieving the list of issues I need but I am getting an error on:
ComponentManager.getInstance().getIssueManager().updateIssue
Code is below:
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.search.SearchProvider import com.atlassian.jira.jql.parser.JqlQueryParser import com.atlassian.jira.web.bean.PagerFilter import com.atlassian.jira.ComponentManager import com.atlassian.jira.security.Permissions import com.atlassian.jira.event.type.EventDispatchOption import com.atlassian.jira.issue.Issue; //Examples, 8 is my subtask issue type id. Will be different for others //changeToSubTaskAndLink("AXDIS-509", "AXDIS-1045", "8") //changeToSubTaskAndLink("AXDIS-509", "AXDIS-1046", "8") def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser.class) def searchProvider = ComponentAccessor.getComponent(SearchProvider.class) def issueManager = ComponentAccessor.getIssueManager() def user = ComponentAccessor.getJiraAuthenticationContext().getUser() //Add first function req here def queryParamsString = "'Functional Requirement Id' ~ 5.3 " //Add all functional reqs after the first here def functionalReqs = ['5.4', '5.5', '5.6', '5.7', '5.8', '5.9', '5.10', '5.11', '5.12'] functionalReqs.eachWithIndex { a, i -> queryParamsString += " OR 'Functional Requirement Id' ~ " + a } def parentIdKey = "AR-2125" def subTaskIssueTypeId = "5" def query = jqlQueryParser.parseQuery("project = AR AND 'Business Requirement Id' ~ '5' AND (" + queryParamsString + ")") def results = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter()) results.getIssues().each {documentIssue -> //log.debug(documentIssue.key) // if you need a mutable issue you can do: def issue = issueManager.getIssueObject(documentIssue.id) // do something to the issue... //changeToSubTaskAndLink("AR-2125", "AR-1977", "5") changeToSubTaskAndLink(parentIdKey, documentIssue.key, subTaskIssueTypeId) } //Method to do all the work def changeToSubTaskAndLink(parentId, childId, subTaskIssueTypeId) { //Get the parent Issue def parent = ComponentManager.getInstance().getIssueManager().getIssueObject(parentId) //Get the child Issue def child = ComponentManager.getInstance().getIssueManager().getIssueObject(childId) //Change the child to the subtask type child.setIssueTypeId(subTaskIssueTypeId) //Update the issue ComponentManager.getInstance().getIssueManager().updateIssue(ComponentManager.getInstance().jiraAuthenticationContext?.user, child, EventDispatchOption.DO_NOT_DISPATCH, false) //Create the subtask link, if this is not done you'll end up with orphans ComponentManager.getInstance().getSubTaskManager().createSubTaskIssueLink(parent, child, ComponentManager.getInstance().jiraAuthenticationContext?.user) }
I get the following error message
Error! No signature of method: com.atlassian.jira.issue.managers.DefaultIssueManager.updateIssue() is applicable for argument types: (com.atlassian.jira.user.DelegatingApplicationUser, com.atlassian.jira.issue.IssueImpl, com.atlassian.jira.event.type.EventDispatchOption$EventDispatchOptionImpl, java.lang.Boolean) values: [canatalio(canatalio), AR-1974, com.atlassian.jira.event.type.EventDispatchOption$EventDispatchOptionImpl@56262ec0, ...] Possible solutions: updateIssue(com.atlassian.crowd.embedded.api.User, com.atlassian.jira.issue.MutableIssue, com.atlassian.jira.event.type.EventDispatchOption, boolean), updateIssue(com.atlassian.jira.user.ApplicationUser, com.atlassian.jira.issue.MutableIssue, com.atlassian.jira.issue.UpdateIssueRequest) groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.managers.DefaultIssueManager.updateIssue() is applicable for argument types: (com.atlassian.jira.user.DelegatingApplicationUser, com.atlassian.jira.issue.IssueImpl, com.atlassian.jira.event.type.EventDispatchOption$EventDispatchOptionImpl, java.lang.Boolean) values: [canatalio(canatalio), AR-1974, com.atlassian.jira.event.type.EventDispatchOption$EventDispatchOptionImpl@56262ec0, ...] Possible solutions: updateIssue(com.atlassian.crowd.embedded.api.User, com.atlassian.jira.issue.MutableIssue, com.atlassian.jira.event.type.EventDispatchOption, boolean), updateIssue(com.atlassian.jira.user.ApplicationUser, com.atlassian.jira.issue.MutableIssue, com.atlassian.jira.issue.UpdateIssueRequest) at Script24.changeToSubTaskAndLink(Script24.groovy:57) at Script24$_run_closure2.doCall(Script24.groovy:44) at Script24.run(Script24.groovy:38)
Community moderators have prevented the ability to post new answers.
I resolved this issue by using the following:
//Update the issue ComponentAccessor.getIssueManager().updateIssue((ApplicationUser)ComponentManager.getInstance().jiraAuthenticationContext?.user, (MutableIssue)child, UpdateIssueRequest.builder().build()) //Create the subtask link, if this is not done you'll end up with orphans ComponentAccessor.getSubTaskManager().createSubTaskIssueLink(parent, child, ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser())
Instead of these depreciated methods
//Update the issue ComponentManager.getInstance().getIssueManager().updateIssue(ComponentManager.getInstance().jiraAuthenticationContext?.user, child, EventDispatchOption.DO_NOT_DISPATCH, false) //Create the subtask link, if this is not done you'll end up with orphans ComponentManager.getInstance().getSubTaskManager().createSubTaskIssueLink(parent, child, ComponentManager.getInstance().jiraAuthenticationContext?.user)
Here is the full script
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.search.SearchProvider import com.atlassian.jira.jql.parser.JqlQueryParser import com.atlassian.jira.web.bean.PagerFilter import com.atlassian.jira.ComponentManager import com.atlassian.jira.security.Permissions import com.atlassian.jira.event.type.EventDispatchOption import com.atlassian.jira.issue.Issue; import com.atlassian.jira.issue.MutableIssue; import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.user.ApplicationUser; import com.atlassian.jira.issue.UpdateIssueRequest; def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser.class) def searchProvider = ComponentAccessor.getComponent(SearchProvider.class) def issueManager = ComponentAccessor.getIssueManager() def user = ComponentAccessor.getJiraAuthenticationContext().getUser() //Add first function req here def queryParamsString = "'Functional Requirement Id' ~ 5.3 " //Add all functional reqs after the first here def functionalReqs = ['5.4', '5.5', '5.6', '5.7', '5.8', '5.9', '5.10', '5.11', '5.12'] functionalReqs.eachWithIndex { a, i -> queryParamsString += " OR 'Functional Requirement Id' ~ " + a } def parentIdKey = "AR-2125" def subTaskIssueTypeId = "5" def query = jqlQueryParser.parseQuery("project = AR AND 'Business Requirement Id' ~ '5' AND (" + queryParamsString + ")") def results = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter()) results.getIssues().each {documentIssue -> //log.debug(documentIssue.key) // if you need a mutable issue you can do: def issue = issueManager.getIssueObject(documentIssue.id) changeToSubTaskAndLink(parentIdKey, documentIssue.key, subTaskIssueTypeId) } //Method to do all the work def changeToSubTaskAndLink(parentId, childId, subTaskIssueTypeId) { //Get the parent Issue def parent = ComponentManager.getInstance().getIssueManager().getIssueObject(parentId) //Get the child Issue MutableIssue child = (MutableIssue)ComponentManager.getInstance().getIssueManager().getIssueObject(childId) //Change the child to the subtask type child.setIssueTypeId(subTaskIssueTypeId) //Update the issue ComponentAccessor.getIssueManager().updateIssue((ApplicationUser)ComponentManager.getInstance().jiraAuthenticationContext?.user, (MutableIssue)child, UpdateIssueRequest.builder().build()) //Create the subtask link, if this is not done you'll end up with orphans ComponentAccessor.getSubTaskManager().createSubTaskIssueLink(parent, child, ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()) }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.