Hello,
I have used the “create a sub-task” feature of Script Runner/Listener to create multiple sub-tasks for a specific issue type. Then I noticed the order of the subtasks I added changes when the issue type is being created. I would like to have the subtasks in an order. Is there a way to do that?
Thanks in advance.
Hi Elif,
Creating subtasks via Listener is async, which means that the order is not something that you can control. On the other hand, using a post function will create the subtasks with the order you define them, from top to bottom in the transaction's post functions. If you want to go with the listener, then you can control the order by writing a custom listener where you can define the order the subtasks will be created.
Thanos,
To use the post functions for this occasion, I need to create a specific work flow which associated with this issue type, right?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If I understand right, you want to change the order of the subtasks depending on the issue type ? If that is the case creating a new workflow would be an overkill. I would propose to do this via a custom post function or custom listener. If I remember well we discussed a very similar issue through support some time ago and we came up with a custom script, I think you can use that script with minor modifications.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I can make the small changes on that script except to add the project name. This issue type is being used by several projects and I would like to be sure to have the subtasks on the correct project. Can I send you the script for you to add the project name? Thanks in advance!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you want to paste it here, I can have a look. Please add comments in the script what exactly you want to achieve, because I don't think I understand completely.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please see the script below. I need to work this script on a projectname=ITSC only. Can you please add that option to it?
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
def parentIssue = event.issue
if (parentIssue.getIssueTypeObject().getName() != 'Employee Termination')
return
def user = ComponentAccessor.getJiraAuthenticationContext().getUser()
def summariesList = ["Subtask 0",
"Subtask 1",
"Subtask 2",
"Subtask 3",
"Subtask 4",
"Subtask 5",
"Subtask 6",
"Subtask 7",
"Subtask 8",
"Subtask 9"]
def issueFactory = ComponentAccessor.getIssueFactory()
def subTaskManager = ComponentAccessor.getSubTaskManager()
def constantManager = ComponentAccessor.getConstantsManager()
def issueManager = ComponentAccessor.getIssueManager()
summariesList.each { subTaskSummary ->
MutableIssue newSubTask = issueFactory.getIssue()
newSubTask.setParentObject(parentIssue)
newSubTask.setProjectObject(parentIssue.getProjectObject())
newSubTask.setPriorityId(constantManager.getPriorityObjects().find {
it.getName() == "Major"
}.id)
newSubTask.setIssueTypeId(constantManager.getAllIssueTypeObjects().find{
it.getName() == "Sub-task"
}.id)
newSubTask.setReporter(parentIssue.reporter ? parentIssue.reporter : null)
// Add any other fields you want for the newly created sub task
Map<String,Object> newIssueParams = ["issue" : newSubTask] as Map<String,Object>
issueManager.createIssueObject(user.directoryUser, newIssueParams)
subTaskManager.createSubTaskIssueLink(parentIssue, newSubTask, user.directoryUser)
log.info "Issue with summary ${newSubTask.summary} created"
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
All you have to do is to add a check in the beginning of your code, in the same way you check if the parent issue type is not Employee Termination then do nothing (return),
if (parentIssue.projectObject.name != "ITSC") return
If you wanted to check the key then parentIssue.projectObject.key and so on...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have tried to run it and for some reason it does not create any of the subtasks. Any ideas?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Are you sure that the ITSC is the name of the project and not the key ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here is the original script we used before. It looks like all I have to do is to remove the part says" copy the JIRA issue description next to the subtasks? Can you help to remove only that part?
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
def parentIssue = event.issue
if (parentIssue.getIssueTypeObject().getName() != 'Employee Termination')
return
def user = ComponentAccessor.getJiraAuthenticationContext().getUser()
def summariesList = ["Subtask 1",
"Subtask 2",
"Subtask 3",
"Subtask 4",
"Subtask 5",
"Subtask 6",
"Subtask 7",
"Subtask 8",
"Subtask 9"]
def issueFactory = ComponentAccessor.getIssueFactory()
def subTaskManager = ComponentAccessor.getSubTaskManager()
def constantManager = ComponentAccessor.getConstantsManager()
def issueManager = ComponentAccessor.getIssueManager()
summariesList.each { subTaskSummary ->
MutableIssue newSubTask = issueFactory.getIssue()
newSubTask.setSummary(subTaskSummary + " - " + parentIssue.getDescription())
newSubTask.setParentObject(parentIssue)
newSubTask.setProjectObject(parentIssue.getProjectObject())
newSubTask.setPriorityId(constantManager.getPriorityObjects().find {
it.getName() == "Major"
}.id)
newSubTask.setIssueTypeId(constantManager.getAllIssueTypeObjects().find{
it.getName() == "Sub-task"
}.id)
newSubTask.setReporter(parentIssue.reporter ? parentIssue.reporter : null)
// Add any other fields you want for the newly created sub task
Map<String,Object> newIssueParams = ["issue" : newSubTask] as Map<String,Object>
issueManager.createIssueObject(user.directoryUser, newIssueParams)
subTaskManager.createSubTaskIssueLink(parentIssue, newSubTask, user.directoryUser)
log.info "Issue with summary ${newSubTask.summary} created"
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The line
newSubTask.setSummary(subTaskSummary + " - " + parentIssue.getDescription())
concat in the subtask summary the description of the parent issue. If you want just the summary
newSubTask.setSummary(subTaskSummary)
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.
Thanos,
The scripts you have provided does not work anymore. I am getting error messages from 4,8,25,35 and 36th lines. Here are the error messages i am getting.
Can you please help me with it? Thanks!
Here is the entire script.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
def parentIssue = event.issue
if (parentIssue.getIssueTypeObject().getName() != 'Job Change/Transfer Form')
return
def user = ComponentAccessor.getJiraAuthenticationContext().getUser()
def summariesList = ["aa",
"bb.)",
"cc",
"dd"]
def issueFactory = ComponentAccessor.getIssueFactory()
def subTaskManager = ComponentAccessor.getSubTaskManager()
def constantManager = ComponentAccessor.getConstantsManager()
def issueManager = ComponentAccessor.getIssueManager()
summariesList.each { subTaskSummary ->
MutableIssue newSubTask = issueFactory.getIssue()
newSubTask.setSummary(subTaskSummary)
newSubTask.setParentObject(parentIssue)
newSubTask.setProjectObject(parentIssue.getProjectObject())
newSubTask.setPriorityId(constantManager.getPriorityObjects().find {
it.getName() == "Major"
}.id)
newSubTask.setIssueTypeId(constantManager.getAllIssueTypeObjects().find{
it.getName() == "Sub-task"
}.id)
newSubTask.setReporter(parentIssue.reporter ? parentIssue.reporter : null)
// Add any other fields you want for the newly created sub task
Map<String,Object> newIssueParams = ["issue" : newSubTask] as Map<String,Object>
issueManager.createIssueObject(user.directoryUser, newIssueParams)
subTaskManager.createSubTaskIssueLink(parentIssue, newSubTask, user.directoryUser)
log.info "Issue with summary ${newSubTask.summary} created"
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Elif did you upgrade to JIRA v7 ? If that is the case have a look at the guide. In your case you should replace:
Line 5: if (parentIssue.getIssueType().getName() != 'Job Change/Transfer Form')
Line 8: def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
Line 25: newSubTask.setPriorityId(constantManager.getPriorities()....
Line 35: issueManager.createIssueObject(user, newIssueParams)
Line 36: subTaskManager.createSubTaskIssueLink(parentIssue, newSubTask, user)
Also keep in mind that there are some times that you can safely ignore the static type checking
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, IT department updated all the Atlassian products last week.
What should I replace the below line with???
newSubTask.setPriorityId(constantManager.getPriorityObjects().find {
it.getName() == "Major"
}.id)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanos,
I have changed all the lines you have mentioned above except the line 25 for the script pasted below, For some reason it does not create the subtasks at all.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
def parentIssue = event.issue
if (parentIssue.getIssueType().getName() != 'New Employee')
return
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def summariesList = ["AA",
"BB,
"CC",
"DD",
"EE"]
def issueFactory = ComponentAccessor.getIssueFactory()
def subTaskManager = ComponentAccessor.getSubTaskManager()
def constantManager = ComponentAccessor.getConstantsManager()
def issueManager = ComponentAccessor.getIssueManager()
summariesList.each { subTaskSummary ->
MutableIssue newSubTask = issueFactory.getIssue()
newSubTask.setSummary(subTaskSummary + " - " + parentIssue.getDescription())
newSubTask.setParentObject(parentIssue)
newSubTask.setProjectObject(parentIssue.getProjectObject())
newSubTask.setPriorityId(constantManager.getPriorityObjects().find {
it.getName() == "Major"
}.id)
newSubTask.setIssueTypeId(constantManager.getAllIssueTypeObjects().find{
it.getName() == "Sub-task"
}.id)
newSubTask.setReporter(parentIssue.reporter ? parentIssue.reporter : null)
// Add any other fields you want for the newly created sub task
Map<String,Object> newIssueParams = ["issue" : newSubTask] as Map<String,Object>
issueManager.createIssueObject(user, newIssueParams)
issueManager.createIssueObject(user, newIssueParams)
log.info "Issue with summary ${newSubTask.summary} created"
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
the line 25 is
newSubTask.setPriorityId(constantManager.getPriorities().find { it.getName() == "High" }.id)
and try again.
PS. I am also sure that in the original request there were two versions of the script, one for JIRAv6.* and one for JIRA v.7.*
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanos, the line 25 worked great thank you!!!
However i cannot login and see the original request, it does not let me to login!
Can you please paste that script for the subtasks that you have created for V 7.0?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.MutableIssue def parentIssue = event.issue if (parentIssue.getIssueType().getName() != 'New Employee') return def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() def summariesList = ["summary1", "summary2", "summary3", "summary4", "summary5", "summary6"] def issueFactory = ComponentAccessor.getIssueFactory() def subTaskManager = ComponentAccessor.getSubTaskManager() def constantManager = ComponentAccessor.getConstantsManager() def issueManager = ComponentAccessor.getIssueManager() summariesList.each { subTaskSummary -> MutableIssue newSubTask = issueFactory.getIssue() newSubTask.setSummary(subTaskSummary) newSubTask.setParentObject(parentIssue) newSubTask.setPriorityId(constantManager.getPriorities().find { it.getName() == "High" }.id) newSubTask.setProjectObject(parentIssue.getProjectObject()) newSubTask.setIssueTypeId(constantManager.getAllIssueTypeObjects().find{ it.getName() == "Sub-task" }.id) // Add any other fields you want for the newly created sub task log.debug("New issue ${newSubTask}") Map<String,Object> newIssueParams = ["issue" : newSubTask] as Map<String,Object> issueManager.createIssueObject(user, newIssueParams) subTaskManager.createSubTaskIssueLink(parentIssue, newSubTask, user) log.info "Issue with summary ${newSubTask.summary} created" }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
This script above does not create any sub-tasks. Any idea why?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanos,
even though there are no error messages coming from the scrips above they dont create sub-tasks anymore. Please help!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
the version we are using is v7.1.1, not sure if that is the reason.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Elif just tested it in my local instance (JIRA v7.1.1) works as expected, as a listener during an issue update. Do you get any errors in your logs ? Do you make sure that the parent issue is of type New Employee ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanos,
I have been creating it exactly the same as before, please see the attachment. It does not give me any error messges, it just does not create any subtasks at all.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
could you please attach the listener configuration screen ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please let me know, if you have any other questions
Script works on the Sandbox as you said BUT not on the Production JIRA.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
ok try to change the priority to something that exists (I can see that the Major is a valid priority for your instance).
newSubTask.setPriorityId(constantManager.getPriorities().find { it.getName() == "Major" }?.id)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanos,
IT IS WORKING
You are awesome!!!!
I get the warning message of " since V 7.0 @line 25 , column 30. But it is working
Thank you so much!!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanos,
I have couple of questions about the script you have provided above, would you be willing to help?
Please let me know.
Thank you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
sure Elif,
Just open a new thread...
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.