Custom single line text field with value is being recognized as EMPTY when queried

Aaron Andrade April 21, 2021

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?

1 answer

0 votes
Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 21, 2021

Hi @Aaron Andrade can you share details about used postfunction which fills the custom field with a value?

Aaron Andrade April 21, 2021

Hi @Martin Bayer _MoroSystems_ s_r_o__ , 

It is a Scriptrunner custom script post-function. 

Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 21, 2021

Hi @Aaron Andrade ok, but what is the script? It is probably some bug in the script, so we need to see it :)

Aaron Andrade April 21, 2021

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
Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 21, 2021

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.

Aaron Andrade April 21, 2021

@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)
Aaron Andrade April 21, 2021

@Martin Bayer _MoroSystems_ s_r_o__  Thank you. I will look into a possible index related cause.

Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 21, 2021

@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()
}
Aaron Andrade April 21, 2021

Removed comment since I didn't see reply before this.

Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 21, 2021

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)
}

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.15.0
TAGS
AUG Leaders

Atlassian Community Events