title: Jira scriptrunner script field: on a custom field, calculate value of other custom fields and display total
body: <p>I am trying to create a custom field that displays the calculated value of 4 other custom fields.  </p>
  
  <p>I need to get the field, get the value, change the value to an integer (they are single select fields) and then calculate the fields value.</p>
  
  <p>Here is the code I have that isn't working:</p>
  
  <pre><code>import com.atlassian.jira.ComponentAccessor
  import com.atlassian.jira.component.ComponentAccessor
  import com.atlassian.jira.ComponentManager
  import com.atlassian.jira.issue.CustomFieldManager
  import com.atlassian.jira.issue.fields.CustomField
  import com.atlassian.jira.issue.IssueManager
  import com.atlassian.jira.issue.Issue
  
  
  def bvField = ComponentAccessor().getCustomFieldManager().getCustomfFieldObjectbyName("BV")
  def bvValue = issue.getCustomFieldValue(bvfield)
  def tcField = ComponentAccessor().getCustomFieldManager().getCustomfFieldObjectbyName("TC")
  def tcValue = issue.getCustomFieldValue(tcField)
  def rrField = ComponentAccessor().getCustomFieldManager().getCustomfFieldObjectbyName("RR")
  def rrValue = issue.getCustomFieldValue(rrField)
  def jobSizeField = ComponentAccessor().getCustomFieldManager().getCustomfFieldObjectbyName("Job Size Field")
  def jobSizeValue = issue.getCustomFieldValue(jobSizeField)
  
  def jobSizeInt = Integer.parseInt(jobSizeValue)
  def rrInt = Integer.parseInt(rrValue)
  def tcInt = Integer.parseInt(tcValue)
  def bvInt = Integer.parseInt(bvValue)
  
  def total = (bvInt + tcInt + rrInt) / jobSizeInt
  
  
  if (bvValue!="none" &amp;&amp; tcValue!="none" &amp;&amp; rrValue!="none" &amp;&amp; jobSizeValue!="none") {
      return total
      } else {
      return 85
  }
  </code></pre>