Hi all.
I'm trying to create a behavior that takes the parent summary and display it in the summary field in the create subtask screen. This is so that the user can more easily create subtasks for stories when there is only one subtask. It is then very often just a copy of the parent summary.
I simply cannot get it to work. I've tried to follow what is described here:
https://scriptrunner.adaptavist.com/latest/jira/recipes/behaviours/subtask-default-fields.html
I've followed what it say in the link and put this on the summary field and not in the initializer as the parentID is null then.
This is my script:
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.onresolve.jira.groovy.user.FieldBehaviours
public class CopySummaryFromParentToSubtask extends FieldBehaviours {
public Object run() {
FormField parent = getFieldById("parentIssueId")
log.warn("CopySummaryFromParentToSubtask parent: " + parent)
Long parentIssueId = parent.getFormValue() as Long
IssueManager issueManager = ComponentAccessor.getIssueManager()
MutableIssue parentIssue = issueManager.getIssueObject(parentIssueId)
log.warn("CopySummaryFromParentToSubtask parentIssue.summary: " + parentIssue.summary)
def summaryField = getFieldById("Summary")
log.warn("CopySummaryFromParentToSubtask summaryField: " + summaryField)
summaryField.setFormValue(parentIssue.summary)
log.warn("CopySummaryFromParentToSubtask summaryField: " + summaryField)
}
}
The Summary field is not updated at all. It's completely blank. I can input values all over the place and still nothing happens in the screen. In the log however it does print out all my debug statements with the values I expect. Everything looks fine when looking at the log.
Also I would like to be able to focus on the summary field and have it all selected so that if the user do want to create a different summary they don't have to erase the summary, they can simply start to type. I haven't found any setFocus(true) or setSelected(true) method that is available. Any suggestions for this?
All in all maybe behavior isn't the right thing to use for this?