It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

getting information from task to subtask tickets

Surender Reddy Apr 01, 2019

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...

 

 

4 comments

Antoine Berry Community Leader Apr 01, 2019

Hi,

This is possible with an add-on such as scriptrunner.

Like Surender Reddy likes this
Surender Reddy Apr 01, 2019

Can you explain to me how do it? actually, we are using the scriptrunner now. 

Antoine Berry Community Leader Apr 01, 2019

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

Like Surender Reddy likes this
Surender Reddy Apr 01, 2019

Thank You man this is working.

Antoine Berry Community Leader Apr 02, 2019

Glad to help ! You can mark the answer as accepted to lead other users with similar issues on this topic.

Surender Reddy Apr 08, 2019

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 

Antoine Berry Community Leader Apr 08, 2019

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.

Surender Reddy Apr 08, 2019

I don't see Accept option on this issue page. that's why I liked your answers  

Surender Reddy Apr 08, 2019

I guess this is discussion thts the reason i dont see accept the answer 

Antoine Berry Community Leader Apr 08, 2019

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

CHILLAMCHARLA VARUN Apr 08, 2019

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.

Antoine Berry Community Leader Apr 09, 2019

Yes exactly, you can add this very post function in the subtask transition that leads to the status "Done" in your subtask workflow.

CHILLAMCHARLA VARUN Apr 09, 2019

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??

1.PNG

Antoine Berry Community Leader Apr 09, 2019

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

Like CHILLAMCHARLA VARUN likes this
CHILLAMCHARLA VARUN Apr 09, 2019

Thanks Antoine,

i will work on "Custom script post-function" .

Comment

Log in or Sign up to comment
Community showcase
Published in Jira

Try Jira Cloud for Outlook: Organize your work without leaving your inbox

Hi Atlassian community, My name is Max and I work on the product integration team at Atlassian. I am pleased to announce the early access program for the Jira Cloud add-in for Outlook. This add-in...

2,194 views 6 15
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you