Jira scriptrunner: Need to fetch value of scripted custom field

Parvez Misarwala September 28, 2020

Dear Community

I have an Epic which has 2 stories. The story has a scripted numeric custom field named 'Delivery Estimate'. I want to get the sum of this field from stories to Epic. For this I have created a scripted field "Total Delivery Estimate", and I have written below code to fetch the values of Delivery Estimate at Epic level. The issue I see here is, jira script getcustomfieldvalue, does not fetch the value if custom field is 'scripted field'. Can anyone suggest if this is feasible and what would be the correct code. 

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.link.IssueLinkTypeManager

def customFieldManager = ComponentAccessor.getCustomFieldManager()
IssueLinkTypeManager issueLinkTypeManager = ComponentAccessor.getComponent(IssueLinkTypeManager)
IssueLinkManager issueLinkManager = ComponentAccessor.issueLinkManager

def value=0;

def linkType = issueLinkTypeManager.getIssueLinkTypes(false).find{ it.name == 'Epic-Story Link' }
def issueLinkList = issueLinkManager.getOutwardLinks(issue.id).findAll{ it.getLinkTypeId() == linkType.getId() }

for (issueLink in issueLinkList) {
def childIssue = issueLink.getDestinationObject()
def customField = customFieldManager.getCustomFieldObject('customfield_22601')

int currentValue= childIssue.getCustomFieldValue(customField)
if(currentValue){
value = value + currentValue
}
}
return value ;

1 answer

1 accepted

1 vote
Answer accepted
Gustavo Félix
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 28, 2020

Hi @Parvez Misarwala 
I had a similar problem.
My workaround was to save that scripted field into another custom field . 
That way I can fetch from the "normal" custom field instead of the scripted field.

Code inside your story scripted field:
.....
.....
calculate the value to return , lets call it X 
save X inside your "normal" custom field 
return X 

Parvez Misarwala September 29, 2020

Thats perfect..Thanks a lot @Gustavo Félix 

Like Gustavo Félix likes this

Suggest an answer

Log in or Sign up to answer