Hey guys,
i am not SW developer so please excuse any beginner questions.
I am trying to calculate the sum of a specific custom field for all issues of one type.
My understanding is that If you use scripts inside the listener the scripts are always run for a one issue. This means that I can only access the values of a specific custom field per issue.
How do I manage to access all my project issues inside a listener script?
(it is fine it the script is run each time one of my project issues is changed)
Best regards
CG
See:
Issue1 - Custom Field1 = 2
Issue2 - Custom Fied2 = 3
Issue3 - Custom Field3 = 2
The sum is 7.
If my understanding is correct, then the code below can help you See:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
def customField = ComponentAccessor.getComponent(CustomFieldManager)
def cf = customField.getCustomFieldObjectByName('Name of your Custom Field')
def issueMgr = ComponentAccessor.getIssueManager()
def listIssues = issueMgr.getIssueObjects(issueMgr.getIssueIdsForProject(Your Project Id))
def sum = 0
listIssues.each { elem ->
if (elem.getIssueType().getName() == 'Name of your Reques type' && elem.getCustomFieldValue(cf) != null){
sum += elem.getCustomFieldValue(cf)
}
}
Could you answer a question?
1) Shouldn't you choose besides "Issue Updated" the option "Issue Created" too? Because, a new issues will have
the custom field with value, will not?
You can use the code in "Script Console" (Jira Administration -> Manage Apps -> ScriptRunner -> Console)
I look forward to your reply
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
See:
Issue1 - Custom Field1 = 2
Issue2 - Custom Fied2 = 3
Issue3 - Custom Field3 = 2
The sum is 7.
If my understanding is correct, then the code below can help you See:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
def customField = ComponentAccessor.getComponent(CustomFieldManager)
def cf = customField.getCustomFieldObjectByName('Name of your Custom Field')
def issueMgr = ComponentAccessor.getIssueManager()
def listIssues = issueMgr.getIssueObjects(issueMgr.getIssueIdsForProject(Your Project Id))
def sum = 0
listIssues.each { elem ->
if (elem.getIssueType().getName() == 'Name of your Reques type' && elem.getCustomFieldValue(cf) != null){
sum += elem.getCustomFieldValue(cf)
}
}
Could you answer a question?
1) Shouldn't you choose besides "Issue Updated" the option "Issue Created" too? Because, a new issues will have
the custom field with value, will not?
You can use the code in "Script Console" (Jira Administration -> Manage Apps -> ScriptRunner -> Console)
I look forward to your reply
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
See:
Issue1 - Custom Field1 = 2
Issue2 - Custom Fied2 = 3
Issue3 - Custom Field3 = 2
The sum is 7.
If my understanding is correct, then the code below can help you See:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
def customField = ComponentAccessor.getComponent(CustomFieldManager)
def cf = customField.getCustomFieldObjectByName('Name of your Custom Field')
def issueMgr = ComponentAccessor.getIssueManager()
def listIssues = issueMgr.getIssueObjects(issueMgr.getIssueIdsForProject(Your Project Id))
def sum = 0
listIssues.each { elem ->
if (elem.getIssueType().getName() == 'Name of your Reques type' && elem.getCustomFieldValue(cf) != null){
sum += elem.getCustomFieldValue(cf)
}
}
Could you answer a question?
1) Shouldn't you choose besides "Issue Updated" the option "Issue Created" too? Because, a new issues will have
the custom field with value, will not?
You can use the code in "Script Console" (Jira Administration -> Manage Apps -> ScriptRunner -> Console)
I look forward to your reply
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.