Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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

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

Hi @Martin Bayer _MoroSystems_ s_r_o__ , 

It is a Scriptrunner custom script post-function. 

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

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

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.

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

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

@Michelle Douma 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()
}

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

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

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you