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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.