Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

JQL for "issuekey in updatedBy()" doesn't find issues updated via a ScriptRunner job?

David Merrill
Contributor
February 1, 2024

Hi all,

I'm using a ScriptRunner job to update a custom field in Jira Data Center 9.4, like this:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.user.util.UserManager

UserManager userManager = ComponentAccessor.userManager
ApplicationUser user = userManager.getUserByName("automation-user")

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
IssueManager issueManager = ComponentAccessor.getComponent(IssueManager.class)

MutableIssue issue = issueManager.getIssueByCurrentKey("FOOBAR-10175")
CustomField myCustomFieldField = customFieldManager.getCustomFieldObjectsByName("My Custom Field").first()

IssueIndexingService issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService)

String myCustomField = "2"
issue.setCustomFieldValue(myCustomFieldField,myCustomField)

//
// Register the changes for the issue
issueManager.updateIssue(
user,
issue,
EventDispatchOption.ISSUE_UPDATED,
true
)

issueIndexingService.reIndex(issue)

 

The update happens fine and I can see the change in the issue history. However, the issue doesn't show up when I use the following JQL query:

issuekey = "FOOBAR-10175" and issuekey in updatedBy("automation-user"))

I do see the results if I search for the value of the field, like this:

issuekey = "FOOBAR-10175" and "My Custom Field" ~ "2"

So I know the issue got re-indexed properly after the update was made. The "issuekey in updatedBy()" clause works for other changes that have been made so I think I might need to add something to my script to get the right trail in place for the changes I'm making in the script. Any ideas what might be missing?

1 answer

1 accepted

0 votes
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
February 1, 2024

Hi @David Merrill

For your requirement, I suggest using ScriptRunner's HAPI feature to simplify your code. You also do not need to execute the re-indexing service, as HAPI will handle it.

Below is a sample working HAPI code template for your reference:-

import com.adaptavist.hapi.jira.issues.Issues

def issue = Issues.getByKey('<ISSUE_KEY>')
def myCustomField = '<Value>'

issue.update {
setCustomFieldValue('<FIELD_NAME>', myCustomField)
}

Below is the full use of the template:-

import com.adaptavist.hapi.jira.issues.Issues

def issue = Issues.getByKey('FOOBAR-10175')
String myCustomField = '2'

issue.update {
setCustomFieldValue('My Custom Field', myCustomField)
}

Please note that the sample code above is not 100% exact to your environment. Hence, you will need to make the required modifications.

Also, when using ScriptRunner's Job, you do not need to specify which user is updating the field value in the code, as you will already have set the user in the Job configuration.

Hence, in the sample code above, I am not including the user details.

Note: To use ScriptRunner's HAPI feature, your ScriptRunner version must be at least 7.11.0.

It would be best to upgrade your ScriptRunner plugin to the latest release, i.e. 8.20.0.

I hope this helps to solve your question. :-)

Thank you and Kind regards,

Ram

 

David Merrill
Contributor
February 2, 2024

Thanks for the response, @Ram Kumar Aravindakshan _Adaptavist_ !

HAPI certainly does make this process easier and I like the clarity of the code you provided.

Unfortunately changes I make with this code are still not seen with 'issuekey in updatedBy("<user>")' JQL queries.  There must be something missing from changes made this way since I do see manually entered changes in other tickets when querying with this JQL function.

Ram Kumar Aravindakshan _Adaptavist_
Community Champion
February 2, 2024

Hi @David Merrill

Thank you for getting back and providing your feedback.

I did a test on my environment along with one of our developers; this does seem like a Bug.

Please create a new Bug report on our Support Portal and include the steps to replicate the issue. It would be best to provide a short test video so the Support Engineers can refer to it to replicate the issue and create the Bug report.

Please also include the version of Jira and ScriptRunner you tested.

Thank you and Kind regards,

Ram

David Merrill
Contributor
February 2, 2024

Will do, thank you @Ram Kumar Aravindakshan _Adaptavist_ !

Ram Kumar Aravindakshan _Adaptavist_
Community Champion
February 4, 2024

Hi @David Merrill

A Bug report has been created for this issue. For your reference, the Bug report number is SRJIRA-7054.

Kindly accept the answer provided.

Thank you and Kind regards,

Ram

Suggest an answer

Log in or Sign up to answer