Script to decrement a number field

I am trying to decrement a number field.  I am trying to use the following script to do so as a post function.  However, the number is not decrementing.  What am I doing wrong?

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;
// gets a reference to the IssueManager and CustomFieldManager manager classes
IssueManager issueManager = ComponentManager.getInstance().getIssueManager();
CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager();
// gets a reference to the desired issue and custom field
CustomField customField_count1 = customFieldManager.getCustomFieldObjectByName( "Number of Code Defects" );
CustomField customField_count2 = customFieldManager.getCustomFieldObjectByName( "Number of Requirement Defects" );
// retrieves the custom field value object from the issue
Object count1 = issue.getCustomFieldValue( customField_count1 ) - 1;
Object count2 = issue.getCustomFieldValue( customField_count2 ) - 1;
issue.setCustomFieldValue(customField_count1, count1);
issue.setCustomFieldValue(customField_count2, count2);



1 answer

That script looks OK at first glance. Presuming it's the first post-function in the list, that should work.

You could add some log messages to check what the values are, eg

log.warn ("count2: $count2")


Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,422 views 15 19
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you