Hello everyone,
I have used a post function script in an issue to perform a transition in another issue. When the transition in original issue is performed, the target issues are also transitioned from Closed to “In Progress” status as seen in View issue screen of target issues. But in issue navigator screen, the issues are still shown in previous status i.e. closed
Why are they not getting updated in Jira DB?
Here is the current rough script:
package P3
import P3.Helper.P3_PackageUnitHelper
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.bc.issue.IssueService.TransitionValidationResult
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.web.bean.PagerFilter
//import com.atlassian.jira.util.thread.JiraThreadLocalUtils
import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.issue.MutableIssue
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
import groovy.transform.Field
import org.apache.log4j.Logger
@field final Logger LOG = Logger.getLogger(this.class)
@field String REVOKE_SIGN_OFF_TRANSITION_NAME = "Revoke Sign-Off"
ApplicationUser currentUser = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
SearchService searchService = ComponentAccessor.getComponent(SearchService)
IssueService issueService = ComponentAccessor.getComponent(IssueService)
P3_PackageUnitHelper packageUnitHelper = new P3_PackageUnitHelper(LOG)
Issue packIssue = this.getProperty("issue") as Issue
//MutableIssue mutableIssue = ComponentAccessor.getIssueManager().getIssueObject(packIssue.getKey())
String packageUnitsProjectName = P3_Constants.Project.PACKAGE_UNITS.name
String signOffStatusFieldName = P3_Constants.Field.SIGN_OFF_STATUS.name
String parentPackageFieldName = P3_Constants.Field.PARENT_PACKAGE.name
String jqlQuery = "project = \"$packageUnitsProjectName\" AND \"$signOffStatusFieldName\" in (Granted, Overruled) and \"$parentPackageFieldName\" = ${packIssue.key}"
SearchService.ParseResult parseResult = searchService.parseQuery(currentUser, jqlQuery)
// Thread.start {
//Thread executorThread = new Thread(JiraThreadLocalUtils.wrap {
if (parseResult.isValid()) {
List packageUnitIssueList = searchService.search(currentUser, parseResult.getQuery(), PagerFilter.getUnlimitedFilter()).getResults()
int updatedPackageUnitsCounter = 0
packageUnitIssueList.each {packageUnitIssue ->
int transitionId = packageUnitHelper.getWorkflowStepIdByName(packageUnitIssue, REVOKE_SIGN_OFF_TRANSITION_NAME)
/*TransitionValidationResult transitionValidationResult =
issueService.validateTransition(currentUser, packageUnitIssue.id, transitionId, issueService.newIssueInputParameters())
if (transitionValidationResult.isValid()) {
IssueService.IssueResult result = issueService.transition(currentUser, transitionValidationResult)*/
def transitionValidationResult = issueService.validateTransition(currentUser, packageUnitIssue.id, transitionId, issueService.newIssueInputParameters())
if (transitionValidationResult.isValid()) {
def result = issueService.transition(currentUser, transitionValidationResult)
//ComponentAccessor.getComponent(IssueIndexingService).reIndex(packageUnitIssue)
if (result.isValid()) {
updatedPackageUnitsCounter++
//Re-index the issue after update
boolean wasIndexing = ImportUtils.isIndexIssues()
ImportUtils.setIndexIssues(true)
ComponentAccessor.getComponent(IssueIndexingService.class).reIndex(packageUnitIssue)
ImportUtils.setIndexIssues(wasIndexing)
} else {
LOG.error("There was a problem while revoking the Sign-Off for ${packageUnitIssue.key}")
LOG.error(result.getErrorCollection())
}
} else {
LOG.error("The Sign-Off could not be revoked for ${packageUnitIssue.key}")
LOG.error(transitionValidationResult.getErrorCollection())
}
}
if(updatedPackageUnitsCounter < packageUnitIssueList.size()) {
UserMessageUtil.warning("Sign-Off was only revoked for $updatedPackageUnitsCounter " +
"of ${packageUnitIssueList.size()} Package Units. Please contact your " +
"administrator for more information")
} else {
UserMessageUtil.success("Sign-Off succesfully revoked for all $updatedPackageUnitsCounter " +
"Package Units!")
}
}
/*})
// start the thread
executorThread.start()*/
Hi @SWAPNIL SRIVASTAV ,
it's an index problem for sure. In your code I see :
def result = issueService.transition(currentUser, transitionValidationResult)
...
ComponentAccessor.getComponent(IssueIndexingService.class).reIndex(packageUnitIssue)
I think that you are reindexing the wrong one. You should :
ComponentAccessor.getComponent(IssueIndexingService.class).reIndex(result.getIssue());
Please, let me know if it fixes your issue.
Fabio
Join us to learn how your team can stay fully engaged in meetings without worrying about writing everything down. Dive into Loom's newest feature, Loom AI for meetings, which automatically takes notes and tracks action items.
Register today!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.