I added a custom field that I want to increment each time the workflow transitions to the status. I read the other posts on this, but didn't find the answer I needed. This is what I have done:
When I transition the issue I get an error that the custom field cannot be updated. I have checked the permissions and screens, and it's there. What else can I do to fix this?
This is the code for the post function:
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue;
String customFieldName = "Counter";
DefaultIssueChangeHolder changeHolder = new DefaultIssueChangeHolder();
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField cf = customFieldManager.getCustomFieldObject(10047);
Double currValue = (Double)cf.getValue(issue);
Double newValue = currValue+1;
cf.updateValue(null, issue, new ModifiedValue(currValue,newValue), changeHolder);
I also tried:
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue;
//Update "Churn Number" to the name of your custom field.
String customFieldName = "Rework";
DefaultIssueChangeHolder changeHolder = new DefaultIssueChangeHolder();
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
//Update "Churn Number" to the name of your custom field.
CustomField cf = customFieldManager.getCustomFieldObject(10047);
//NOTES: If the current value is 0 use 0 not null. If it is a real number use the real number.
def currValue = (Double)cf.getValue(issue) ?: 0
def newValue = currValue+1;
cf.updateValue(null, issue, new ModifiedValue(currValue,newValue), changeHolder);
This is the error:
Unable to update custom field customfield_10047 - Rework in issue [TSP-11].
What did I miss?