Hello team,
In my project we had four Sub:task types: Claim, issue, basket and collect among those tasks i need to manage only one sub:task "basket" not created more than one to parent issue.
Here is the example:
We can see above screen shot the Basket Sub: task created twice but need to restrict only one
Note: we are using script runner in our organization
Please suggest me any suggestions.
Thanks,
Siva.
Hi @siva
Use the condition to check for sub-task exists in the parent issue and implement the delete issue automation based on the condition.
Thanks,
Pramodh
Hi @Pramodh M
Thanks for the early reply Unfortunately we don't have Automation plugin in my instance is it possible by using script runner plug-in. Please help me how to achieve this issue.
Thanks,
Siva
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, Please find the below reference link for Code example
Thanks,
Pramodh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm new to the scriptrunner can you please help me with the below script
import com.atlassian.jira.component.ComponentAccessor
def subtaskToCreateName = "Task"
def issue = ComponentAccessor.getIssueManager().getIssueObject("TEST-1")
//getting subtasks names of given issue
def subtaskIssueTypes = issue.getSubTaskObjects().collect {it.getIssueType().getName()}
//checking if creating subtask alrealdy exist
if (!(subtaskToCreateName in subtaskIssueTypes)){
//your code to create subtask
}
Thanks,
Siva
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @siva
Please find the Code below to add in Scriptrunner Listeners Option for Issue Created event. Let me know if this works
import com.atlassian.jira.event.issue.DelegatingJiraIssueEvent
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.event.issue.IssueEventBundle
import com.atlassian.jira.event.type.EventType
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
def issue = event.issue
def issueManager = ComponentAccessor.getIssueManager()
def parentIssue
if( issue.issueType.subTask ) {
Issue subtaskIssue = issue
log.warn(issue.getParentObject())
parentIssue = issue.getParentObject()
log.warn(parentIssue.subTaskObjects.size())
if ( parentIssue.subTaskObjects.size() == 0 ) {
// Meaning the Parent has either no Sub-task or only 1 Sub-task
log.warn("We are Good")
} else {
log.warn("We are deleting the Sub-task Issue")
log.warn("Total Number of Sub-task: " + parentIssue.subTaskObjects.size())
issueManager.deleteIssueNoEvent(subtaskIssue)
}
} else {
log.warn("This is Standard Issue Type, So we are Good")
}
Thanks,
Pramodh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Pramodh M
Thanks for the reply the above script working fine but it restrict all the sub:tasks not created more than one here i need restrict only single sub:task that is "Sub:Basket" and other sub:tasks can create as many as. Please help me with relevant script.
Thanks,
Siva.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This should work, replace the Sub-task name with the one you want to restrict
import com.atlassian.jira.event.issue.DelegatingJiraIssueEvent
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.event.issue.IssueEventBundle
import com.atlassian.jira.event.type.EventType
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
def issue = event.issue
def issueManager = ComponentAccessor.getIssueManager()
def parentIssue
// Replace the Basket Sub-task Issue Type with one which you want to restrict
if( issue.issueType.name == "Basket" ) {
Issue subtaskIssue = issue
log.warn(subtaskIssue)
log.warn(issue.getParentObject())
parentIssue = issue.getParentObject()
log.warn(parentIssue.subTaskObjects.size())
if ( parentIssue.subTaskObjects.size() == 0 ) {
// Meaning the Parent has either no Sub-task or only 1 Sub-task
log.warn("We are Good")
} else {
log.warn("We are deleting the Sub-task Issue")
log.warn("Total Number of Sub-task: " + parentIssue.subTaskObjects.size())
// log.warn(issueManager.getIssueObject(subtaskIssue))
issueManager.deleteIssueNoEvent(subtaskIssue)
}
} else {
log.warn("This is Standard Issue Type or Sub-task other than the one which you have specified, So we are Good")
}
Thanks,
Pramodh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please accept the Answer If it solved your requirement 🙂
Thanks,
Pramodh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Unfortunately the script not restrict the Basket Sub:task i can able to create Basket task more than one. Please look into the script once again thanks for the patience.
Thanks,
Siva
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you please give me the exact Sub-task Issue name in double quotes?
Thanks,
Pramodh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Use the exact Sub-task name from the Issue Type you have created as shown below
in the line
if( issue.issueType.name == "Basket" )
Thanks,
Pramodh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Actually the sub-task is Sub: Grooming and i used exact sub-task in script please see below the screen shot
Here the subtask
In the line
Thanks,
Siva
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It should work, Can you please make sure by editing the Issue Type it doesn't have any whitespaces or extra spaces.
And exact configuration looks like this
And Code is
import com.atlassian.jira.event.issue.DelegatingJiraIssueEvent
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.event.issue.IssueEventBundle
import com.atlassian.jira.event.type.EventType
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
def issue = event.issue
def issueManager = ComponentAccessor.getIssueManager()
def parentIssue
log.warn(issue.issueType.name)
if( issue.issueType.name == "Sub: Grooming" ) {
Issue subtaskIssue = issue
log.warn(subtaskIssue)
log.warn(issue.getParentObject())
parentIssue = issue.getParentObject()
log.warn(parentIssue.subTaskObjects.size())
if ( parentIssue.subTaskObjects.size() == 0 ) {
// Meaning the Parent has either no Sub-task or only 1 Sub-task
log.warn("We are Good")
} else {
log.warn("We are deleting the Sub-task Issue")
log.warn("Total Number of Sub-task: " + parentIssue.subTaskObjects.size())
// log.warn(issueManager.getIssueObject(subtaskIssue))
issueManager.deleteIssueNoEvent(subtaskIssue)
}
} else {
log.warn("This is Standard Issue Type or Sub-task other than the one which you have specified, So we are Good")
}
Also if it is not working, please send the logs from listener event in Scriptrunner.
Let me know the result. I will have to use the Issue type ID in case this doesn't work
Thanks,
Pramodh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Replaced the code and still it creating the issues
Here the log data
2021-12-15 01:33:50,282 WARN [runner.ScriptBindingsManager]: Sub: Grooming
2021-12-15 01:33:50,282 WARN [runner.ScriptBindingsManager]: This is Standard Issue Type or Sub-task other than the one which you have specified, So we are Good
Here the issue created more than one
Thanks,
Siva
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Good news it starts working after updating the issue type with no extra space and it restrict the type created more than one. But it shows error message instead of that message can we change to "Can't create task more than one" so users can understand why it happens. Once again big thanks your help.
Popup error message
Thanks,
Siva.
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.