The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Jira scriptrunner: Need to fetch value of scripted custom field

Parvez Misarwala
Contributor
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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

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 Champions.
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
Contributor
September 29, 2020

Thats perfect..Thanks a lot @Gustavo FĂ©lix 

Like • Gustavo Félix likes this