Skip to content

Instantly share code, notes, and snippets.

@tarunsapra
Created January 22, 2018 12:21
Show Gist options
  • Save tarunsapra/e2f2e5de899c7c52a39fbee2630ef343 to your computer and use it in GitHub Desktop.
Save tarunsapra/e2f2e5de899c7c52a39fbee2630ef343 to your computer and use it in GitHub Desktop.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.workflow.IssueWorkflowManager
def issueManager = ComponentAccessor.issueManager
def issueService = ComponentAccessor.issueService
def issueWorkflowManager = ComponentAccessor.getComponent(IssueWorkflowManager)
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def parentLink = customFieldManager.getCustomFieldObjectByName('Parent Link')
def customFieldValue = issue.getCustomFieldValue(parentLink)
def parentKey = customFieldValue.key
def parentIssue = issueManager.getIssueByCurrentKey(parentKey)
def startProgressAction = issueWorkflowManager.getAvailableActions(issue, user).find{it.name == "Start Progress"}
def inputParams = issueService.newIssueInputParameters()
def validationResult = issueService.validateTransition(user, parentIssue.id, startProgressAction.id, inputParams)
if (validationResult.valid) {
def issueResult = issueService.transition(user, validationResult)
if (issueResult.valid) {
log.debug "Successfully transitioned $parentIssue.key"
} else {
log.error("Could not transistion $parentIssue.key to in progress following $issue.key")
log.error(issueResult.errorCollection?.errorMessages)
log.error(issueResult.warningCollection?.warnings)
}
} else {
log.error("Could not transistion $parentIssue.key to in progress following $issue.key")
log.error(validationResult.errorCollection?.errorMessages)
log.error(validationResult.warningCollection?.warnings)
}
@tarunsapra
Copy link
Author

Issue workflow manager is important to use, instead of hard-coding transition ids
def startProgressAction = issueWorkflowManager.getAvailableActions(issue, user).find{it.name == "Start Progress"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment