I have this script to automaticly promote sub-tasks
Map doScript(Map params) { MutableIssue issue = params['issue'] as MutableIssue User currentUser = componentManager.getJiraAuthenticationContext().getUser() WorkflowTransitionUtil workflowTransitionUtil = ( WorkflowTransitionUtil ) JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class ); SubTaskManager subTaskManager = ComponentManager.getInstance().getSubTaskManager(); Collection<MutableIssue> subTasks = issue.getSubTaskObjects() if (subTaskManager.subTasksEnabled && !subTasks.empty) { subTasks.each { it -> log.debug ("issue.statusObject.name: " + issue.statusObject.name) workflowTransitionUtil.setIssue(it); workflowTransitionUtil.setUsername(currentUser.name); workflowTransitionUtil.setAction (761) // validate and transition issue if (workflowTransitionUtil.validate()) { log.debug("Ready To Start subtask " + it.key) workflowTransitionUtil.progress(); } } } return params }
How can I check if the transition 761 exists before using workflowTransitionUtil.setAction (761) ?
Use:
def actionExists = com.atlassian.jira.component.ComponentAccessor.getWorkflowManager().getWorkflow(it).getDescriptor().getAction(761) == null
You can also use com.atlassian.jira.workflow.IssueWorkflowManager.isValidAction(Issue, int)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Boris, I changes the code as you suggested
def actionId = 4 IssueManager issueManager = ComponentManager.getInstance().getIssueManager(); MutableIssue issue = issueManager.getIssueObject("ICTST-410"); User currentUser = componentManager.getJiraAuthenticationContext().getUser() WorkflowTransitionUtil workflowTransitionUtil = ( WorkflowTransitionUtil ) JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class ); SubTaskManager subTaskManager = ComponentManager.getInstance().getSubTaskManager(); Collection<MutableIssue> subTasks = issue.getSubTaskObjects() if (subTaskManager.subTasksEnabled && !subTasks.empty) { subTasks.each { it -> log.debug ("issue.statusObject.name: " + issue.statusObject.name) if (com.atlassian.jira.workflow.IssueWorkflowManager.isValidAction(it, actionId)){ workflowTransitionUtil.setIssue(it); workflowTransitionUtil.setUsername(currentUser.name); workflowTransitionUtil.setAction (761) if (workflowTransitionUtil.validate()) { workflowTransitionUtil.progress();
I tried using the code above but I'm getting the following error :
javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: static com.atlassian.jira.workflow.IssueWorkflowManager.isValidAction() is applicable for argument types: (com.atlassian.jira.issue.IssueImpl, java.lang.Integer) values: [ICTST-411, 4]
I guess that the problem is that "it" is not IssueImpl .. how can I fix it?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
you've got a mistake - You should use
com.atlassian.jira.component.ComponentAccessor.getComponent(com.atlassian.jira.workflow.IssueWorkflowManager.class).isValidAction(it,actionId)
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.