问题
In Jira, we have a series of subtasks all belonging to a common parent task. For ease of explanation, these subtasks will referred to as such, and the parent task will be referred to as the lesson.
On each subtask, there is a field 'Percent Complete', which is manually updated by the user as progress is made on the subtask.
The lesson will also have a 'Percent Complete' field, which the user cannot manually update. Instead, I would like it to be updated through the execution of a Groovy script when a subtask's 'Percent Complete' field is updated by a user, since the lesson's Percent Complete will be comprised of the weighted sums of the child subtask's Percent Complete field.
I'm a programmer with no experience in Jira customization. The actual logic behind getting the Percent Complete value for the Lesson task is super simple, but I don't know how to 'hook everything up'. So my question is this:
How can I trigger a field in a parent task (the lesson) to be updated to a calculated value when the value of the child (subtask) field is changed?
My original thought was to create a Custom Scripted Field in the subtask, and in the groovy script which is attached, find its parent task (the lesson), and then iterate through all of its subtasks, performing the relevant calculations on the required fields and then writing the result to a custom field belonging to the parent.
Is this the right approach?
回答1:
A script field is not a good approach for what you try to achieve. A script field gets evaluated and runs its script every time an issue is requested, so it would run far too often for your needs. E.g. it will also run for every issue whenever a jira reindex is performed or whenever a user looks at an issue.
Zeddzull commented with a better approach. In a script listener, you can respond to issue updated events and check which field was updated and only update your parent issue if needed.
More documentation is available here. If you google a bit you'll also find info about how to check for changed fields or how to update a custom field.
Getting your parent issue is as simple as calling the getParentObject() on your issue instance.
来源:https://stackoverflow.com/questions/46528824/jira-scriptrunner-update-a-parents-field-when-modifying-the-childs-field