Hi Team,
i need help for few of my questions and if its possible then how to implement them .
In JIRA workflow for my client ,i have created grrovy script that creates subtask when parent issue is created but now i wanted to add some constraints when a manual subtask is being created for a parent issue.
1. if autocreated subtask exists with same summary then manually new subtask should not be created.
2. if my parent issue is makred to done then also it should not allow to create a new subtask manually.
3. parent issue is marked to done, once all subtasks are done then subtasks should not be allowd to move into other status even if transition from done to inprogress does exist.
Kinldy provide some code or scripts that can help me achiving above mentioned points.
Thanks in advance !
Hey there, I think I have a viable solution for each of your requests. So I'll go through each one-by-one:
1. For your first requirment, it would be easiest to hide the Create-Subtask UI element using one of the built in Script Fragments. You can find these by pressing the "." (period) key while in your JIRA instance and searching for "Script Fragments." The fragment that you want to add is "Hide system or plugin UI element." Once you are in the creation screen for that fragment, add this code to the "Condition" block:
def currentStatus = issue.status.name !(currentStatus == "Done")
And select the create-subtask element from the web-items to hide. The code states that if an issue is in the "Done" status, then the Create-Subtask option will not appear on the issue view screen. Additionally, if you would like to do more than just remove the option from view, you can add a script validator to the Create transition, similar to the route I take below.
2. For your second requirment, you need to make a simple script validator on the Create transition in your workflow (if you need assistance in setting that up, let me know). The condition you use should look something like this:
if(issue.isSubTask()) { def issueParent = issue.getParentObject() def parentSubTasks = issueParent.getSubTaskObjects() def currentSubTaskSummary = issue.getSummary() !parentSubTasks.find{it.getSummary() == currentSubTaskSummary} }
This condition checks every other subtask assigned to its parent issue and ensures that the subtask being created is not a duplicate. Add an appropriate error message and leave the Field box blank (make sure you publish the workflow after adding the validator).
3. For your third requirment, you need to add another workflow validator to every transition that is not your "Done" transition. I wasen't quite sure what you were asking for in the third point, so this is what I came up with:
if(issue.isSubTask()) { if(issue.getParentObject().status.name == "Done") { !issue.status.name == "Done" } else { true } } else { true }
This condition essentially makes it so that a subtask cannot transition to the status associated with this validator if its parent's status is set to "Done." Again, add the appropriate error message and leave the Field box blank. Just to reiterate, this validator must be added to every transition that is not your "Done" transition to ensure that a subtask cannot be set to any of those statuses.
That's all I've got! Let me know if you need help or further clarification with any of this!
Best,
Aidan
Hi Aiden - i have similar need for the first one but instead of stopping manual sub-task from being created, i want to stop a duplicate from being created on the transition (if the workflow went back a step and then forward again).
any ideas on this one?
thanks
Tracey
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Tracey!
Assuming you are using the Create Subtask SR post-function, you should be able to use a condition like this to check if the issue already has a subtask with the given summary:
import com.atlassian.jira.component.ComponentAccessor
def subtasks = issue.subTaskObjects
if(subtasks.find{it.summary == "Subtask Summary"})
{
return false
}
else
{
return true
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Aidan,
I have the exact requirement to prevent sub-task creation(1 issue in the above question) so can you please guide me where do i need to add this code in script runner as i am new to jira cloud.
Thanks.
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.