I'm having trouble finding simple issue transition code that actually functions in Jira Cloud. I'm trying to set up a ScriptRunner listener for issue updates.
When specific criteria are met (Through my own code logic, not transition validation which I know doesn't work in cloud) I'm trying to transition my issue status. No matter what I do though, I'm still getting the error 'unable to resolve class IssueService'.
Being on cloud, I can't import the proper packages, and I can't find a simple solution anywhere that fits my use case. How can I actually use any of the IssueService methods, or what alternatives am I supposed to use in Cloud?
Thanks in advance.
Edit: Here's my code after much finagling.
/*Modified from following source:
https://community.atlassian.com/t5/Marketplace-Apps-questions/ScriptRunner-how-to-change-status-of-an-Issue/qaq-p/628842
*/
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueManager = ComponentAccessor.issueManager
def issue = issueManager.getIssueObject(event.issue.key)
IssueService issueService = ComponentAccessor.getIssueService()
def actionId = 10017 //Transition ID
def customFieldManager = ComponentAccessor.getCustomFieldManager()
if (issue.getStatus().name == "Unassigned" && issue.getAssigneeUser() != null) {
transitionResult = issueService.transition(currentUser, transitionValidationResult)
//Find docs for transition, replace transitionValidationResult
if (transitionResult.isValid()) {
log.debug("Transitioned issue $issue through action $actionId")
}
else {
log.debug("Transition result is not valid")
}
}
Post your script. Doing what you describe is possible with SR on Jira Cloud.
Updated the top post. I haven't been able to test it at all, because it keeps failing at line 8, unable to resolve class.
IssueService issueService = ComponentAccessor.getIssueService()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Those classes aren't available via Cloud. You'll want to use the supplied binding and hit the API directly or everything else.
// use issue.fields to read your issue fields and check that you hit your condition
logger.info(issue.fields)
// call the transitions endpoint to execute the transition
post(
"/rest/api/2/issue/${issue.key}/transitions"
)
.header(
"Content-Type"
,
"application/json"
)
.body([
transition: [
id: transitionID
]
])
.asString()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.