You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.
View groupJoin the community to find out what other Atlassian users are discussing, debating and creating.
I have a requirement where I need to add values from multiple number fields and perform math operation on them. Then I need that result stored in another custom field for use in Portfolio (since Portfolio does not support scripted fields).
FieldA = number field
FieldB = number field
cdField = Scripted number field to store sum of FieldA+FieldB
FieldD = number field
jsField = Scripted number field to store result of cdField/jsField
wsjfField = number field
I have worked out the scripts for cdField and jsField but have two problems to overcome:
1. When I set searcher for wsjfField to "Number Searcher" this line has an error in the script editor (red squiggly under / ):
return FieldC / FieldD
If I set the searcher to none it works without error
2. On jsField script I need to have code that takes the return value that takes that calculated value and updates another custom field (wsjfField) to that value (wsjfValue) so it can be used in Portfolio.
This is my relevant code for jsField:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField jsField = customFieldManager.getCustomFieldObject("customfield_15123")
CustomField cdField = customFieldManager.getCustomFieldObject("customfield_15126")
CustomField wsjfField = customFieldManager.getCustomFieldObject("customfield_15128")
String jsValue = issue.getCustomFieldValue(jsField).toString()
String cdValue = issue.getCustomFieldValue(cdField).toString()
int jsInt = Integer.parseInt(jsValue)
int cdInt = Integer.parseInt(cdValue)
def wsjfValue = cdInt/jsInt
//need code here to update wsjfField value in this issue to wsjfValue
return cdInt / jsInt
I have tried various code samples to update custom fields but they all get errors to where I gave up and figure I ask here if this is even possible from a scripted field.
Hi Peter,
You can fix it by change:
String jsValue = issue.getCustomFieldValue(jsField).toString()
String cdValue = issue.getCustomFieldValue(cdField).toString()
To:
def jsValue = issue.getCustomFieldValue(jsField) as Double
def cdValue = issue.getCustomFieldValue(cdField).toString() as Double
Remove:
//int jsInt = Integer.parseInt(jsValue)
//int cdInt = Integer.parseInt(cdValue)
//def wsjfValue = cdValue/jsValue
Return:
return cdValue/jsValue
So your final code should be:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField jsField = customFieldManager.getCustomFieldObject("customfield_15123")
CustomField cdField = customFieldManager.getCustomFieldObject("customfield_15126")
CustomField wsjfField = customFieldManager.getCustomFieldObject("customfield_15128")
def jsValue = issue.getCustomFieldValue(jsField) as Double
def cdValue = issue.getCustomFieldValue(cdField) as Double
return cdValue/jsValue
It is recommended to return as Double and not Integer since you are dividing the 2 numbers.
Hello everyone, I am a product manager in the Jira Cloud team focused on making sure our customers have a delightful experience using our products. Towards that goal, one of the areas which is extr...
Connect with like-minded Atlassian users at free events near you!
Find an eventConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.
Host an eventYou're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.