上QQ阅读APP看书,第一时间看更新
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 into Jira with a user that has a Jira administrator's permission.
- Navigate to Administration > Issues > Custom fields.
- Click on the Add Custom Field button and select Advanced from the dialog box.
- Scroll down and select Scripted Field from the list; 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 Administration > Manage apps > Script Fields.
- Select the Edit option for the Total Comments field.
- Enter the following Groovy script in the script text box:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.comments.CommentManager
def commentManager = ComponentAccessor.getCommentManager()
def numberOfComments = commentManager.getComments(issue).size()
return numberOfComments ? numberOfComments as Double : null
- Select Number Field for Template and click on Update, as shown in the following screenshot:
When the custom field is added to an issue, it will automatically calculate the number of comments the issue has in real time, as shown in the following screenshot:
Now it's time to look to understand the steps.