How to increment number field via post function?

Andreas P November 13, 2018

Is it possible to increment a custom number field in a post function?
I tried it with Update Any Issue Field (JSU) function, but it only let's me set it to one specific value, but not to currentValue+1.

2 answers

0 votes
Joffrey_Hamman May 29, 2020

An example of scriped postfunction to increment a custom number field:

import com.atlassian.jira.ComponentAccessor
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.customfields.CustomFieldType
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.util.IssueChangeHolder
import com.atlassian.jira.issue.IssueManager
CustomFieldManager cfManager = ComponentAccessor.getCustomFieldManager()
IssueManager issueManager = ComponentAccessor.getIssueManager()

// In "customfield_15201" replace 15201 by the ID of your custom number field
CustomField cf = cfManager.getCustomFieldObject("customfield_15201")
Double val = issue.getCustomFieldValue(cf) as Double

if (val)
val = val + 1
else
val = 1
issue.setCustomFieldValue(cf, val)
0 votes
David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 13, 2018

Hi Andréas,

JMWE has a specific post-function for that, but you can also achieve the same with other apps such as ScriptRunner and a little code for example. 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events