本文介绍了Jira Scriptrunner - 修改孩子的字段时更新父母的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Jira中,我们有一系列子任务都属于一个共同的父任务。为了便于解释,这些子任务将被称为这样,并且父任务将被称为课程。

在每个子任务上,都有一个字段完成百分比,由用户在子任务上取得进展时手动更新。



课程也会有一个'完成百分比'栏位,用户不能手动更新。相反,当用户更新子任务的完成百分比字段时,我希望通过执行Groovy脚本来更新它,因为课程的完成百分比将由子子任务的完成百分比字段的加权总和组成。

我是一个没有Jira定制经验的程序员。获得课程任务完成百分比值的实际逻辑非常简单,但我不知道如何勾住一切。所以我的问题是这样的:



当子任务的子任务(子任务)被触发时,如何触发父任务(课程)中的字段更新为计算值)字段已更改?



我最初的想法是在子任务中创建自定义脚本字段,并在附加的groovy脚本中查找其父任务(课程),然后遍历其所有子任务,在必填字段上执行相关计算,然后将结果写入属于父级的自定义字段。



这是正确的方法?

解决方案

脚本字段不是您尝试实现的好方法。每次请求问题时,都会对脚本字段进行评估并运行其脚本,因此它会针对您的需求运行得太频繁。例如。它也会运行每一个问题,无论何时执行jira reindex或每当用户查看问题。



Zeddzull评论了一个更好的方法。在脚本侦听器中,您可以响应问题更新的事件并检查哪个字段已更新,并且只在需要时更新您的父问题。

更多文档可用。
如果你有一点点谷歌,你还可以找到有关如何检查更改字段或如何更新自定义字段的信息。



获取您的父母问题与调用。


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?

解决方案

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.

这篇关于Jira Scriptrunner - 修改孩子的字段时更新父母的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 19:42