Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
  • Community
  • Q&A
  • Jira
  • Questions
  • Jira scriptrunner created issues not found via JQL query when created and searched in same script

Jira scriptrunner created issues not found via JQL query when created and searched in same script

Beppe Marcon June 12, 2018

I have a script which first creates a bunch of issues via something like:

issueService = ComponentAccessor.getIssueService()
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.setIssueTypeId(issueTypeId)
issueInputParameters.setProjectId(projectId)
issueInputParameters.setSummary(summary)
issueInputParameters.setReporterId(user.getName())

CreateValidationResult createValidationResult = validateIssue(user, issueInputParameters)

if(createValidationResult == null)
{
return null
}
else
{
IssueResult createResult = issueService.create(user, createValidationResult)

}

and then does a query searching for the created issues:

def queryTemplate = "issueFunction in hasLinks(\"References ONE\") and issue in linkedIssues(${one.key}) and issue in linkedIssues(${homeNet.key})"

def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def compiledQuery = jqlQueryParser.parseQuery(query)
log.debug "${query}"
ApplicationUser user = "myUser"
SearchResults searchResults = searchProvider.search(compiledQuery, user, PagerFilter.getUnlimitedFilter())

 

When run, the script creates the issues correctly, but these are not available to the JQL query (searchResults returns empty result), this until a second execution of the same code is run.

It seems in other words that the issues are persisted at script's execution end so I need to run the code two times for the issues to be available via JQL query.

 

 

 

 

 

2 answers

0 votes
Noni Khutane
Contributor
July 15, 2020

Were you able to resolve this issue?

0 votes
Prakhar Srivastav {Appfire}
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 12, 2018

@Beppe Marcon

You have to do reindex explicitly after you create the issues and before you search by jql.

boolean wasIndexing = ImportUtils.isIndexIssues()
ImportUtils.setIndexIssues(true)
ComponentAccessor.getIssueIndexManager().reIndex(issue)
ImportUtils.setIndexIssues(wasIndexing)

Regards

Prakhar

Beppe Marcon June 13, 2018

Hi, I added a reindex as you suggested, below is the non-deprecated version of your code:

boolean wasIndexing = ImportUtils.isIndexIssues()
ImportUtils.setIndexIssues(true)
IssueIndexManager indexManager = ComponentAccessor.getComponent(IssueIndexManager)
indexManager.reIndex(issue)
ImportUtils.setIndexIssues(wasIndexing)

however the problem persists, I'm afraid the problem is the re-indexing of the linked issues. In my code I create a new Issue and two links to other issues, the JQL as I previously posted is the following:

"issueFunction in hasLinks(\"References ONE\") and issue in linkedIssues(${one.key}) and issue in linkedIssues(${homeNet.key})"

 I'm afraid the problem is the reindexing of all links created.

Prakhar Srivastav {Appfire}
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 13, 2018

@Beppe Marcon

 

Can you try to use reIndex with IssueIndexingParams? It gives you the ability to index issue related metadata also. You can also use IssueIndexService instead of IssuIndexManager as I see the later is being deprecated. But at this moment both should work.

Here is the api description :

https://docs.atlassian.com/software/jira/docs/api/7.3.5/com/atlassian/jira/issue/index/IssueIndexManager.html#reIndex-com.atlassian.jira.issue.Issue-com.atlassian.jira.issue.index.IssueIndexingParams-

https://docs.atlassian.com/software/jira/docs/api/7.3.5/com/atlassian/jira/issue/index/IssueIndexingService.html#reIndex-com.atlassian.jira.issue.Issue-com.atlassian.jira.issue.index.IssueIndexingParams-

If it also does not solve then I fear you have to use reindexAll().

 

Regards

Prakhar

Beppe Marcon June 13, 2018

I added a:


IssueIndexManager indexManager = ComponentAccessor.getComponent(IssueIndexManager)
indexManager.reIndexAll()

and the JQL fails, if I run the same query from web console it returns the correct result, same if I rerun the script after the issue and linked issues have been created.

should I get worried?

Prakhar Srivastav {Appfire}
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 13, 2018

@Beppe Marcon

Did you add a check if the reindex is complete ?

Run jql only after reindex is complete.

 

Regards

Prakhar

Beppe Marcon June 13, 2018
IssueIndexingService indexService = ComponentAccessor.getComponent(IssueIndexingService)
long reindexTime = indexService.reIndexAll()
await(reindexTime)
Beppe Marcon June 25, 2018

ok fixed

Suggest an answer

Log in or Sign up to answer