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
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(project.id)
def fieldValueA = (valueB - valueC) / issueCount
return fieldValueA
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.