You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
Hi friends,
I am trying to create subtask automatically in a transaction from a task. I did it with post functions. My question is can we get the information we gave at task creation to subtask (for example custom fields at task creation ) can anyone explain the process .\
Thanks in advance...
Can you explain to me how do it? actually, we are using the scriptrunner now.
Go in the subtask workflow and add a Script Post-Function [ScriptRunner] postfunction in the create transition.
You need to specify your code. Here is a snippet that updates the current issue custom field with the parent custom field value (change the custom field id) :
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.component.ComponentAccessor
//Your custom field ID
int cfId = 10100
def cf = customFieldManager.getCustomFieldObject(cfId)
def cfValue = issue.getCustomFieldValue(cf)
def cfParentValue = issue.getParentObject().getCustomFieldValue(cf)
cf.updateValue(null, issue, new ModifiedValue(cfValue, cfParentValue), new DefaultIssueChangeHolder())
Of couse make sure that this workflow is only used by the sub-task you want to apply this update to. Else you need to add a condition to this script to check the Issue type.
Antoine
Glad to help ! You can mark the answer as accepted to lead other users with similar issues on this topic.
Hi friend,
In a project, I am working with the main task and that create subtask and then at the end to the main task. Is there any way we can move the main ticket to next stage after all subtasks are closed automatically.
Thank YOU
Hi,
This is possible indeed. If you are satisfied with the initial answer, could you mark it as accepted ? I will come back some feedback on your question.
I don't see Accept option on this issue page. that's why I liked your answers
Ah, too bad. Thanks for all the likes. :)
So here is quick example of how you can achieve it, but of course you need to adapt it to your specifics.
This is assuming the "closed" status in your sub-task workflow is "Done". In your sub-task workflow, Add a post-function to your transition that leads to "Done" status at the last place. The script here checks if all the the subtasks of the parent are "Done", and proceeds to trigger a transition.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl
import com.atlassian.jira.workflow.WorkflowTransitionUtil
import com.atlassian.jira.util.JiraUtils
Integer subTaskDone = 0
Issue parentIssue = issue.getParentObject()
def parentSubTasks = parentIssue.getSubTaskObjects()
Integer subTaskCount = parentSubTasks.size()
String parentStatus = parentIssue.getStatus().getName()
for (currSubTask in parentSubTasks){
if (currSubTask.getStatus().getName() == "Done") {
subTaskDone++
}
}
if (subTaskCount == subTaskDone){
int transitionId
if (parentStatus == "In Progress"){
//The transition to trigger
transitionId = 51
}
else if (parentStatus == "To Do"){
transitionId = 41
}
if (transitionId){
//The user that triggers the transition. Make sure he has the permission to trigger it.
String currentUserKey = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser().getKey()
WorkflowTransitionUtil workflowTransitionUtil = ( WorkflowTransitionUtil ) JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class );
workflowTransitionUtil.setIssue(parentIssue);
workflowTransitionUtil.setUserkey(currentUserKey)
workflowTransitionUtil.setAction(transitionId);
workflowTransitionUtil.progress();
}
}
I hope that is what you are looking for.
Antoine
Hello Antoine,
Can you help me where to add above code in post-function?
--> i have to to add in "Script Post-Function [ScriptRunner]" ? or which post-function?
Thanks.
Yes exactly, you can add this very post function in the subtask transition that leads to the status "Done" in your subtask workflow.
Hello Antoine,
thanks for info. see the below screenshot when i click on the ""Script Post-Function" i need to follow the "Transition parent when all subtasks are resolved" step??
Well I guess you can use this one, I did not notice it until now. My script would work with the "Custom script post-function", so it is up to you