- JIRA 6.x Administration Cookbook
- Patrick Li
- 373字
- 2021-12-08 12:37:37
Creating custom field with custom logic
All custom fields that come out of the box with JIRA have predefined purposes, such as text field, which allows users to type in some simple text. It will often be useful to have a specialized custom field that does exactly what you need. Unfortunately, this often requires custom development efforts.
However, there is an add-on that provides a custom field type that lets you use Groovy scripts to power its logic.
In this recipe, we will look at how to create a custom field that uses a Groovy script to display the total number of comments on any given issue.
Getting ready
For this recipe, we need to have the Script Runner add-on installed. You can download it from the following link or install it directly from the Universal Plugin Manager at https://marketplace.atlassian.com/plugins/com.onresolve.jira.groovy.groovyrunner.
You may also want to get familiar with Groovy scripting at http://groovy.codehaus.org.
How to do it…
Creating a scripted field is a two-step process. We first need to create an instance of the custom field in JIRA and then add the script to it:
- Log in to JIRA as a JIRA administrator.
- Navigate to Administration | Issues | Field Configurations.
- Click on the Add Custom Field button and select Advanced from the dialog box.
- Scroll down and select Scripted Field from the list, and click on Next, as shown in the following screenshot:
- Name our new custom field
Total Comments
, and add it to the appropriate screens. - Navigate to Add-ons | Script Fields.
- Click on the Edit link for the Total Comments field.
- Enter the following Groovy script in the script text box:
import com.atlassian.jira.ComponentManager def commentManager = ComponentManager.getInstance().getCommentManager() def numberOfComments = commentManager.getComments(issue).size() return numberOfComments ? numberOfComments as Double : null
- Select Number Field for Script Template, and click on OK as shown in the following screenshot:
How it works…
The scripted field type is an example of what is called calculated custom field type. The calculated custom field type is a special custom field that derives (calculates) its value based on some predefined logic, in this case, our Groovy script. Every time the field is displayed, JIRA will recalculate the field's value so it is always kept up to date.
- 資本的眼睛
- 金融科技(FinTech)發展的國際經驗和中國政策取向(中國金融四十人論壇書系)
- Big Data Visualization
- SAP ABAP Advanced Cookbook
- 從零開始學房地產會計
- IBM SPSS Modeler Cookbook
- 內審人員進階之道:內部審計操作實務與案例解析
- 計量經濟學理論與應用:基于Eviews的應用分析
- Microsoft Dynamics CRM 2016 Customization(Second Edition)
- 看穿一切數字的統計學
- 統計原理與實務
- 多項目管理方法及其應用研究(國家社科基金后期資助項目)
- 2014年注冊會計師(CPA)全國統考專用輔導教材系列:審計(名師解讀版)
- 人口預測模型研究及應用
- TIBCO Spotfire for Developers