Not able to use JQL with Script runner updated Custom Field

Hi ,

updated the Text Field (single line) using script runner  , the script runner has updated the CustomFiled , but  not able to query using JQL with updated customField , it is not displaying any rows if updated custom Field used in JQL , but the value has been updated , updated column is Test_Email with Value 1001

Tried with Text & number in updation 

def tgtField = customFieldManager.getCustomFieldObjects(myIssue).find {it.name == "Test_Email"}
def changeHolder = new DefaultIssueChangeHolder();
tgtField.updateValue(null, myIssue, new ModifiedValue(issue.getCustomFieldValue(tgtField), "1001"),changeHolder);

Output from Database

mysql> select * from customfieldvalue where issue=(select id from jiraissue where issuenum='2079') and CUSTOMFIELD=11300;
+-------+-------+-------------+-----------+-------------+-------------+-----------+-----------+-----------+
| ID | ISSUE | CUSTOMFIELD | PARENTKEY | STRINGVALUE | NUMBERVALUE | TEXTVALUE | DATEVALUE | VALUETYPE |
+-------+-------+-------------+-----------+-------------+-------------+-----------+-----------+-----------+
| 41245 | 15500 | 11300 | NULL | 1001 | NULL | NULL | NULL | NULL |
+-------+-------+-------------+-----------+-------------+-------------+-----------+-----------+-----------+
1 row in set (0.00 sec)

Screen Shot After updating using the Script runner 

Jira_Jql.pngJira1_Jql.pngJira2_Jql.png 

2 answers

1 accepted

2 votes

You should use IssueService to update which will do the proper re-indexing for you after the update: https://docs.atlassian.com/jira/latest/com/atlassian/jira/bc/issue/IssueService.html#update-com.atlassian.jira.user.ApplicationUser-com.atlassian.jira.bc.issue.IssueService.UpdateValidationResult-

Here is some example code of how to use it in your script:

import com.atlassian.jira.component.ComponentAccessor

def user = ComponentAccessor.jiraAuthenticationContext.user.directoryUser
def issueManager = ComponentAccessor.issueManager
def issueService = ComponentAccessor.issueService

def issue = issueManager.getIssueObject("KEY")
def issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.setDescription("Updated description")

def validationResult = issueService.validateUpdate(user, issue.id, issueInputParameters)

if (validationResult.isValid()) {
    issueService.update(user, validationResult)
    log.info("Updated issue")
} else {
    log.info("Invalid update")
    log.info(validationResult.errorCollection)
}

@Gabrielle Bautista [ACP-JA] @Adam Markham [Adaptavist]

Thanks for support 

After reindexing it's works fine ,

Added  indexManager.reIndex(issue); in the code to  Reindex the field 

 

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published yesterday in Jira

Mission-critical battery manufacturer fulfills FAA software requirements with Commit Policy Plugin

EaglePicher Technologies is a leading manufacturer of battery systems for diverse industries like defense, aviation, space or medical. As they operate in highly regulated industries, keeping a clear ...

158 views 0 2
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you