I'm new to Jira and I'm trying to calculate the effort and the costs of an issue based on different values for the effort in the issue. It is no problem to enter the different values for the effort in the issue and display them, but I am not able to display the result of my calculation.
I created Script Field and set the template to "Text Field (Multi Line)". I added the new field to the screen where I want it to be shown. When I use the preview feature for my example issue the preview just shows nothing. I don't get an error either. When I use the Fieldhelper it says, that there is no value set and therefore the field is not displayed. But I don't know why the value is not set, as the code seems to be working fine (no error).
Maybe somebody can point me to where I am wrong?
Here is some example code of what I'm doing:
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;
com.atlassian.jira.issue.MutableIssue;
IssueManager issueManager = ComponentManager.getInstance().getIssueManager()
CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager()
CustomField totalField = customFieldManager.getCustomFieldObjectByName("Total")
def a = issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Effort A"))?:0
def b = issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Effort B"))?:0
Object total = (a * 1500) + (b * 1000)
issue.setCustomFieldValue(totalField, total)
I also tried a different approach and used a number field. The result is the same, there is no error and the field value is not set.
import com.atlassian.jira.ComponentManager
cManager = ComponentManager.getInstance().getCustomFieldManager()
int A = cManager.getCustomFieldObjectByName('Effort A')?.getValue()?:0
int B = cManager.getCustomFieldObjectByName('Effort B')?.getValue()?:0
int C = cManager.getCustomFieldObjectByName('Effort C')?.getValue()?:0
int D = cManager.getCustomFieldObjectByName('Effort D')?.getValue()?:0
int E = cManager.getCustomFieldObjectByName('Effort E')?.getValue()?:0
int F = cManager.getCustomFieldObjectByName('Effort F')?.getValue()?:0
return (A*1500) + (B*1000) + (C*1000) + (D*1300) + (E*375) + (F*1000)