- 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.
- 自愿審計動機與質量研究:基于我國中期財務報告審計的經驗證據
- Citrix XenApp? 7.5 Desktop Virtualization Solutions
- Splunk:Enterprise Operational Intelligence Delivered
- 中國特色社會主義國家審計制度研究
- 博弈論及其在經濟管理中的應用
- 國家治理能力視角的國家審計功能理論研究
- Microsoft Dynamics CRM 2011 Scripting Cookbook
- 陜西文物年鑒·2015
- 從零開始學房地產會計
- Tableau:Creating Interactive Data Visualizations
- 2017年度注冊會計師全國統一考試專用教材(圖解版):審計
- Stata統計分析與行業應用案例詳解(第2版)
- 內審人員進階之道:內部審計操作實務與案例解析
- 看穿一切數字的統計學
- Microsoft Dynamics CRM 2016 Customization(Second Edition)