How to create a script runner field

nhungttt148 April 2, 2024

Hi guys, 

I want to create a custom field called A that can be calculated: 

A = (customfield B - customfield C)/ count all number ticket of project X

Pls guide me in writing a runner script to create the above field

Thank you so much,

Note: Field B, C are datetime picker field type and A is number field

1 answer

0 votes
Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 2, 2024

Hi @nhungttt148 

There are some ambiguous parts (e.g. is custom field B and C a number field?) but you can use below code as a start


import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()
def projectManager = ComponentAccessor.getProjectManager()

// Retrieve the custom fields by their names or IDs
// You can also use getCustomFieldObject("customfield_xxxx") to obtain by id
def fieldB = customFieldManager.getCustomFieldObjectByName("CustomField B")
def fieldC = customFieldManager.getCustomFieldObjectByName("CustomField C")

// Retrieve numeric values from custom fields B and C
def valueB = issue.getCustomFieldValue(fieldB) as Double // or you can use 'as Long', depending on the field's data type
def valueC = issue.getCustomFieldValue(fieldC) as Double

def project = projectManager.getProjectObjByKey("X")
def issueCount = issueManager.getIssueCountForProject(

def fieldValueA = (valueB - valueC) / issueCount

return fieldValueA

Suggest an answer

Log in or Sign up to answer