Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Issue Transition in Jira Cloud (ScriptRunner)

Jon Hollister
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 23, 2018

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")
}
}

 

1 answer

0 votes
Randy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 23, 2018

Post your script. Doing what you describe is possible with SR on Jira Cloud.

Jon Hollister
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 24, 2018

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()
Randy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 24, 2018

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

https://developer.atlassian.com/cloud/jira/platform/rest/#api-api-2-issue-issueIdOrKey-transitions-post

post("/rest/api/2/issue/${issue.key}/transitions")          
.header("Content-Type", "application/json")          
.body([              
transition: [                  
id: transitionID              
]          
])          
.asString()
Like # people like this

Suggest an answer

Log in or Sign up to answer