Scriptrunner listener to set filed value

arno
Contributor
June 30, 2024

大家好

我想通过设置脚本监听器来统计某个问题下用户的评论数。我的想法是:设置一个map变量,记录用户评论时的操作者信息,并将变量值赋给text类型的字段。但是不知道该如何优化代码,目前代码如下:


 

导入 com.atlassian.jira.component.ComponentAccessor

导入 com.atlassian.jira.issue.CustomFieldManager

导入 com.atlassian.jira.issue.Issue

导入 com.atlassian.jira.issue.MutableIssue
导入 com.atlassian.crowd.embedded.api.User

def issue = event.issue 作为问题

def field = customFieldManager.getCustomFieldObject( 'customfield_10700' )
def value = issue.getCustomFieldValue(field)

def 用户= 当前用户.name
定义 数字= 1

定义 地图=[:]

map.put(用户,数字)

问题.setCustomFieldValue(字段,地图)
log.错误(地图)
log.error(字段)

2 answers

0 votes
YY Brother
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 30, 2024

Hi @arno 

为什么不用 Jira 自动化实现?不用写一行代码

触发器:已添加事务评论

Action:编辑事务(每次有新评论,自定义字段+1)

Thanks,
YY哥

arno
Contributor
June 30, 2024

hi @YY Brother 

如果只是增加字段值,这个目前我能实现,我需要记录的是用户在某个issue里面评论的次数,我查看了下自动化,也需要通过代码方式获取对应的操作人

 

YY Brother
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 30, 2024

了解,如果是:

user 1 : 3

user 2: 4

xxx

然后 users 个数不确定的话,那么得想其他办法实现了。

arno
Contributor
June 30, 2024

users确实不能确定,而且我们还需要进一步判断用户所属的群组,并不是所有的评论都需要统计到(我们有做一些系统的集成,集成账号也会触发一些评论)

0 votes
arno
Contributor
June 30, 2024

If this can be done, I want to make another judgment, when the user has commented before, then numer++, I want the last issue to close, this text field can record the corresponding information like: [test1:3,test2:2,test3:10]

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events