We have a custom field that gets automatically assigned a value through a workflow post-function. The value is based off the highest existing number in that field in all other tickets in the project. The script is supposed to take the highest value + 1 then add that new number to the new ticket field. However, often that field is being recognized as empty in some tickets, so duplicate values are being assigned when ideally that shouldn't ever happen.
Correct example:
1. custom_field = E100
2. custom_field = E101 (E100 + 1)
3. custom_field = E102 (E101 + 1)
Example of the issue we're experiencing:
1. custom_field = E100
2. custom_field = E101 (E100 + 1)
3. custom_field = E101 (E100 + 1) <-- WRONG
In the issue example, when the query ran for #3 it did not recognize that the value for #2 existed and was the highest value.
Has anyone else experienced a similar issue?
Hi @Aaron Andrade can you share details about used postfunction which fills the custom field with a value?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Aaron Andrade ok, but what is the script? It is probably some bug in the script, so we need to see it :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Martin Bayer _MoroSystems_ s_r_o__ , we confirmed the issue with the query during troubleshooting. Here is our query:
project = myProject AND issuetype = myIssueType AND customTextField is not EMPTY ORDER BY customTextField ASC
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This JQL query works correctly when all the data are correcty indexed. If you do not update the value in custom field correctly (with reindexing the issue), it can cause problems.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Martin Bayer _MoroSystems_ s_r_o__ Here is our script:
import com.atlassian.jira.bc.issue.search.SearchService 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.Issue // get all the used numbers so far def query = ComponentAccessor.getComponent(JqlQueryParser).parseQuery("project = myProject AND issuetype = myIssueType AND customTextField is not EMPTY ORDER BY customTextFIeld ASC") def search = ComponentAccessor.getComponent(SearchService).search(ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(), query, PagerFilter.getUnlimitedFilter()) String eMaxNumbers def customFieldManager = ComponentAccessor.getCustomFieldManager() def cField = customFieldManager.getCustomFieldObject((Long) 17814) // Loop through result set grabbing customTextField for(Issue documentIssue: search.results) { eMaxNumbers = documentIssue.getCustomFieldValue(cField) as String } // Set variable Number by removing the leading 'E' def Number = eMaxNumbers.substring(1) as Integer // Set variable newNumber to Number plus 1 def newNumber = ++Number as String // Concantenate the string 'E' + 00000 + newNumber (the zeros are determined by the length of newNumber (total of 6 digits)) def newID = "E" + "00000".substring(newNumber.length()) + newNumber as String // Set customTextField issue.setCustomFieldValue(cField, newID)
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.
@Aaron Andrade you are using issue.setCustomFieldValue method. I suggest you to use IssueService component (https://docs.atlassian.com/software/jira/docs/api/8.15.1/com/atlassian/jira/bc/issue/IssueService.html) and its methods
Code can be something like:
IssueService.UpdateValidationResult updateValidationResult = issueService.validateUpdate(executingUser, issueId, issueInputParameters);
if (!updateValidationResult.isValid()) {
log.error updateValidationResult.getErrorCollection()
}
IssueService.IssueResult operationResult = issueService.update(executingUser, updateValidationResult);
if (!operationResult.isValid()) {
log.error operationResult.getErrorCollection()
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Removed comment since I didn't see reply before this.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In case you still need to remove "programatically", I'm using following code for this purpose:
def reindex(Collection<MutableIssue> issues) {
def issueIndexManager = ComponentAccessor.getComponent(IssueIndexManager.class)
boolean wasIndexing = ImportUtils.isIndexIssues()
ImportUtils.setIndexIssues(true)
issues.each { issue -> issueIndexManager.reIndex(issue) }
ImportUtils.setIndexIssues(wasIndexing)
}
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.