Forums

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

Groovy condition for 'Issue was in status'

Rob B
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.
February 26, 2020

Im doing a condition to be ....

Issue was previously in status 'Review'

This is basically so i can set a resolution depending on what route the user went around the workflow.

Thanks

2 answers

1 accepted

1 vote
Answer accepted
Payne
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.
February 27, 2020

Here is an example of running JQL in a script:

import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.search.SearchResults
import com.atlassian.jira.user.util.UserUtil
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.web.bean.PagerFilter

String jqlSearch = "status changed from \"Status 1\" to \"Status 2\""
SearchService searchService = ComponentAccessor.getComponent(SearchService.class)
UserUtil userUtil = ComponentAccessor.getUserUtil()
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
IssueManager issueManager = ComponentAccessor.getIssueManager()

List<MutableIssue> issues = null

SearchService.ParseResult parseResult = searchService.parseQuery(user, jqlSearch)
if (parseResult.isValid()) {
SearchResults searchResult = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
issues = searchResult.getResults().collect {issueManager.getIssueObject(it.id)}
} else {
log.error("Invalid JQL: " + jqlSearch);
}
Rob B
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.
February 27, 2020

Hi Payne, thanks so much for you help.

Im getting the below error when i put this into my condition....

Message:
groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.search.SearchResults.getResults() is applicable for argument types: () values: []
Possible solutions: getIssues()
Payne
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.
February 27, 2020

You must be running an older version of Jira than we are (8.5); getIssues() was replaced with getResults() somewhere along the way. My script is an updated version of one that I found at https://community.atlassian.com/t5/Marketplace-Apps-Integrations/How-to-run-JQL-query-inside-Groovy-script/qaq-p/194691 Try that one and see if it works for you.

Rob B
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.
February 27, 2020

Excellent! Thanks again for your help

Rob B
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.
February 27, 2020

Can i ask is it possible to get a results of true or false rather than issues? Thanks

Payne
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.
February 27, 2020

Sure; you can conclude with a line like this:

return issues.size() > 0

Rob B
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.
February 28, 2020

Thanks Payne, but for some reason im not getting the correct result. My JQL is correct when i run that but in this condition its not working it thinks its true. But if i misspell a status it does what its meant to and comes out false. Hope that sort of makes sense?

Payne
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.
February 28, 2020

If it's returning true, then the List must contain one or more issues. Remove the new line (return issues.size() > 0) and see which issues are being returned. You may need to refine your JQL.

0 votes
Payne
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.
February 26, 2020

You can use status was "Some Status"

Rob B
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.
February 27, 2020

Hi Payne, sorry im confused what you mean?

Im looking for a script just like the JQL

status changed FROM "Status 1" TO "Status 2"
Payne
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.
February 27, 2020

Sorry, I thought you were seeking the JQL. I'm attaching a script as a new answer.

Suggest an answer

Log in or Sign up to answer