Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
Level
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

Calling reindex in groovy script listener silently stops all script Edited

Hello

I have a script field ADir Due Date that is being inherited (copied) from linked issues with link type "is parent of" field Due Date and works fine.

When Due Date in the parent issue gets changed, the new ADir Due Date in child issues is calculated and displayed correctly, but JQL ORDER BY ADir Due Date starts to sort wrong. My guess was that child issues need to be reindexed, because reIndexing project in the administration menu helped. So I wrote this script, which works on issue update (modified to try in console):

import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.issue.IssueFieldConstants
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.index.IssueIndexingParams
import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.util.ImportUtils
import org.apache.log4j.Logger

Logger log = log as Logger

def issue = ComponentAccessor.getIssueManager().getIssueObject("ADIRTECH-368");
def issueLinkManager = ComponentAccessor.getIssueLinkManager()

def hasLinkedIssues = issueLinkManager.getOutwardLinks(issue.id).any {issueLink ->
issueLink.issueLinkType.outward == "is parent task of"
}
log.error("hasLinkedIssues ${hasLinkedIssues}")
if(!hasLinkedIssues)
return

def issueMap = new HashSet<Issue>()

def action
def reindex = {Issue reindexingIssue ->
def added = issueMap.add(reindexingIssue);
if(added) {
log.error("Added issue to reindex ${reindexingIssue.key}")
action(reindexingIssue)
}
}

action = {Issue currentIssue ->
log.error("Analyzing linked issues of ${currentIssue.key}")
issueLinkManager.getOutwardLinks(currentIssue.id).each { issueLink ->
log.error("Analyzing issue ${issueLink.destinationObject.key}")
if(issueLink.issueLinkType.outward == "is parent task of") {
def destinationIssue = issueLink.destinationObject
if(destinationIssue.projectObject.key == "ADIRTECH")
return
List<CustomField> allCustomFields = ComponentAccessor.getCustomFieldManager().getCustomFieldObjects(destinationIssue)
def hasADirDueDate = allCustomFields.any { customField -> customField.name == "ADir Due Date" }
log.error("has ADir Due Date ${hasADirDueDate}")
if(hasADirDueDate)
reindex(destinationIssue)
}
}
if(currentIssue != issue) {
currentIssue.subTaskObjects.each { subTask ->
reindex(subTask)
}
}
}
action(issue)

boolean wasIndexing = ImportUtils.isIndexIssues()
ImportUtils.setIndexIssues(true)
log.error("step 1")
try {
ComponentAccessor.getComponent(IssueIndexingService).reIndexIssueObjects(issueMap)
}
catch(Exception exception){
log.error("error", exception)
}
finally{
log.error("finally")
}
log.error("step 2")
ImportUtils.setIndexIssues(wasIndexing)
log.error("step 3")

The last thing i see in logs is:
2019-01-28 18:48:42,441 ERROR [runner.ScriptRunnerImpl]: step 1

The script silently stops when calling reIndex of any kind (reIndex, reIndexIssueObjects) with or without IssueIndexingParams

I have red some posts regarding reindex like:
https://community.atlassian.com/t5/Answers-Developer-Questions/Issue-reindex-from-groovy-script/qaq-p/509901
https://community.atlassian.com/t5/Jira-questions/Scriptrunner-reindex-an-issue/qaq-p/803412
https://community.atlassian.com/t5/Answers-Developer-Questions/What-is-the-best-way-to-reindex-an-issue-modified-in-a-script/qaq-p/471991
etc..

Looks like I'm doing the same thing, but what am I doing wrong?
Any help is appreciated.

P.S. I'm using log.error because lower levels are configured to be not displayed.
P.P.S. issueMap is not empty, I also tried to pass single issue to reIndex method
P.P.P.S. When running this script on issue update, it shows no errors.

Running on Jira Server v7.12.3

1 answer

1 accepted

I have checked atlassian-jira.log and was able to see all expected log lines, so I guess it actually works, just stops logging anything past reIndex method call.

It looks like the script actually reindexes issues, because in the search they appear ordered as expected now..

I'm experiencing the same problem. Script works well, everything is processed and all logs are available in atlassian-jira.log. But debug logging stops as soon as reIndex(...) function is called. I test a single script in Script Console.

If I comment out the reindex function, all debug records keeps printing (just issues are not reindexed, ofc).

Jira: 7.3.6
ScriptRunner: 5.5.9

Really strange, I don't have any explanation for this yet.

Michail, were you able to find the cause for this and resolve it? Thanks.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

New Cloud Apps Roundup - Spring 2021

Atlassian's marketplace partners have had a very productive start to 2021! Since our last roundup, our developer community has added over 160 new cloud apps to the Atlassian Marketplace to help you...

202 views 3 19
Read article

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