Hi All -
I want to create a custom field that gets incremented by +1 every time whenever a new issue creates in Jira project "SSP" and this field has to be visible on create screen and view screen of the issue.
Simply saying, the field should replicate the issue number and this should be done automatically by the system.
I tried with some scripts but getting errors and the script is here
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.search.SearchProvider
// get all the used numbers so far
def query = ComponentAccessor.getComponent(JqlQueryParser).parseQuery("project = SSP AND 'Numbers' is not EMPTY ORDER BY 'Numbers' DESC")
def results = ComponentAccessor.getComponent(SearchProvider).search(query,ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(),new PagerFilter(1))
int maxNumbers = 0
CustomField cField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Numbers")
// get the highest used number
for(Issue documentIssue: results.getIssues())
{ maxNumbers = documentIssue.getCustomFieldValue(cField) as Integer }
// set the new number
def newNumbers = ++maxNumbers as String
//def issue = ComponentAccessor.getComponent(Issue)
issue.setCustomFieldValue(cField, newNumbers)
Please help me out.
Thanks,
Chandra.
Where are you running this script? post functions or script listener?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The above script works as post function. Please see my instructions - https://community.atlassian.com/t5/Jira-discussions/How-to-create-a-numeric-field-with-a-value-that-increments-value/td-p/905858#M10045
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I can't help you with the script, but tying it to the issue ID is going to be a problem. The ID is created at the end of the create process. You would need to run the script in a post function after the issue is created. I haven't tried that so I don't know if it is even possible.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.