How do I default the value of a sub-task field to the value of a parent field?

When users create a sub-task, I want a custom field value on the sub-task to default to the value on the parent when the sub-task screen is displayed. How do I configure/enable/script this?

3 answers

1 accepted

This widget could not be displayed.

Thanks for the suggestions, guys. I ended up solving this a little differently.

I originally had the field as required so I wanted the value set when the screen opened. After rethinking things, I made the field optional and used the JIRA Miscellaneous Workflow Functions plugin to create a post function that sets the field to the value from the parent.

have you considered the case where the parent is updated? should the child update as well?

Is this possible? The below code works if I update the Subtask, but not if I update the parent. If I change the parent, I want all subtasks to be updated.

This widget could not be displayed.

geting/setting customfields can be a bit involved in java/groovy code, so you could use my add-on's configurable copy Listener for that: Slingshot Updatefields.

cheers, Jos

This widget could not be displayed.

jos is right. created custom code can be time consuming so a plugin that speeds that along is ideal. if you hell bent on crafting the custom code though, i created a listener in groovy that ensures the fixversion of the children always matches the fixversion of the parent. you'll find it below if you care to revise to fit your needs.

package com.custom
 
import com.atlassian.jira.event.issue.AbstractIssueEventListener
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.security.JiraAuthenticationContext
import com.atlassian.jira.project.version.Version
import com.atlassian.jira.event.type.EventDispatchOption
import org.apache.log4j.Category
import com.atlassian.jira.issue.changehistory.ChangeHistoryManager
import com.atlassian.jira.issue.history.ChangeItemBean
import java.util.Calendar
import java.util.Date
import java.sql.Timestamp

class TaskVersionListener extends AbstractIssueEventListener {
    Category log = Category.getInstance(TaskVersionListener.class)
 
    @Override
    void issueUpdated (IssueEvent event) {
	log.setLevel(org.apache.log4j.Level.WARN)
	log.debug ("---- TaskVersionListener starts -----")
	log.debug ("issue: ${event.issue} || task: ${event.issue.isSubTask()}")
		
	// method configuration
	Calendar cal = Calendar.getInstance()
	cal.add(Calendar.SECOND, -30)
	Date date = cal.getTime()
	Timestamp threshhold = date.toTimestamp()
	IssueManager issueManager = ComponentAccessor.getIssueManager()
	UserManager userManager = ComponentAccessor.getUserManager()
	ChangeHistoryManager changeHistoryManager = ComponentAccessor.getChangeHistoryManager()

	if (!event.issue.isSubTask()) {
		List <ChangeItemBean> changeItemBeans = changeHistoryManager.getChangeItemsForField(event.issue,"Fix Version")
		changeItemBeans.each { item ->
			log.debug ("Fix Version created at ${item.getCreated()} with threshhold of $threshhold")
			if (item.getCreated().after(threshhold)) {
				log.debug ("green light for item above!")
				event.issue.getSubTaskObjects().each { t ->
					if (!t.getStatusObject().getName().equals("Done")) {
						MutableIssue myIssue = t
						myIssue.setFixVersions(event.issue.getFixVersions())
						issueManager.updateIssue(userManager.getUser("automation"), myIssue, EventDispatchOption.DO_NOT_DISPATCH, false)
					}
				}
			}
		}
	} else {
		List <ChangeItemBean> changeItemBeans = changeHistoryManager.getChangeItemsForField(event.issue,"status")
		changeItemBeans.each { item ->
			log.debug ("created at ${item.getCreated()} with threshhold of $threshhold")
			if (item.getCreated().after(threshhold) && item.getFromString().equals("Done")) {
				log.debug ("green light for item above!")
				MutableIssue myIssue = event.issue
				myIssue.setFixVersions(event.issue.getParentObject().getFixVersions())
				issueManager.updateIssue(userManager.getUser("automation"), myIssue, EventDispatchOption.DO_NOT_DISPATCH, false)
			}
		}
	}
	log.debug ("---- TaskVersionListener ends ------")
    }
}

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

105 views 2 0
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you