Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to check all items closed in a groovy condition?

Hi

We use Smart Checklist app also JMWE. In a workflow condition I wish to check if all items of the checklist are closed or the checklist is empty. In a jql this looks like:

("Smart Checklist" = allItemsClosed() OR Checklists is EMPTY)

How can I do this condition in groovy, i.e. with JMWE Scripted (Groovy) Validator?

Thanks!
Martin

2 answers

1 accepted

0 votes
Answer accepted

Hi @Martin Heini 

you might want to raise a support ticket with the maker of Smart Checklists for that. 
But there is an alternate solution : use jqlSearch in a Scripted condition. Something like:

!!jqlSearch("key=${issue.key} AND ("Smart Checklist" = allItemsClosed() OR "Smart Checklist" is EMPTY)

Hi David

Thanks for the tip. I've tried with Scripted Validator and global function "issues = jqlSearch", but parsing the jql string throws error 'The operator 'is' is not supported by the 'Smart Checklist' field.'

So I've found an alternate solution with Simple scripted validator (ScriptRunner) - this simply requires more lines of codes than a groovy script in JMWE.

If it works in ScriptRunner, it should work in JMWE. Can you share your script?

Hi David

sorry, I'm just back. ok, yes, I'm will be glad if this works also in JMWE. Here my script:

 

// prüft, ob in diesem Issue keine Checkliste vorhanden ist oder ob alle Checklist-Items erledigt sind
// Verwendung in SEB, Team 'Web', Transition 'In Test'
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.bc.issue.search.SearchService;
import com.atlassian.jira.jql.parser.JqlQueryParser;
import com.atlassian.jira.web.bean.PagerFilter;
import org.apache.log4j.Logger
def logger = Logger.getLogger("com.css.scriptedfield")
log.setLevel(org.apache.log4j.Level.INFO)
// ---------------------------------------------------------------------------------------------
// dies hier ist nur eine Fix-Position für die Script-Console und ist im gespeicherten File zu deaktivieren:
//def issue = ComponentAccessor.issueManager.getIssueByCurrentKey("SEB-26846")
// ---------------------------------------------------------------------------------------------

def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchService = ComponentAccessor.getComponent(SearchService)
def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def IssueKey = issue.getKey()
log.debug("-----validieren für Team (Web), ob keine oder eine erledigte Checkliste vorhanden ist ")
log.debug("-----IssueKey: " + IssueKey)
log.debug("-----user: " + user)

def jqlSearch = "key=" + IssueKey + " AND (Team=Web AND ('Smart Checklist' = allItemsClosed() OR 'Smart Checklist' is EMPTY) OR (Team!=Web))"
def query = jqlQueryParser.parseQuery(jqlSearch)

log.debug("---------jqlSearch: " + jqlSearch)
log.debug("---------query: " + query)

def results = searchService .search(user,query, PagerFilter.getUnlimitedFilter())

if (results.total > 0) {
log.debug("-----Resultat: "+results.total+" Validator => true - Transition kann ausgefuehrt werden")
return true
}
else {
log.debug("-----Resultat: "+results.total+" Validator => false - Transition nicht ausfuehren")
return false
}  

@Martin Heini ,

this code should work as-is in a Scripted (Groovy) Validator. However, it could also be greatly simplified:

!!jqlSearch("key=${issue.key} AND (Team=Web AND ('Smart Checklist' = allItemsClosed() OR 'Smart Checklist' is EMPTY) OR (Team!=Web))",1)
Like Martin Heini likes this

Hi David

really great! Thank you very much - and now: Merry Christmas!

Martin

Hi @Martin Heini

We are glad you're using Smart Checklist.

We can say that the solution recommended above is accurate. If you have any additional questions in regards to the usage of the Smart Checklist, feel free to reach out to us at smartchecklist@railsware.com.

Best regards,

Olena

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.13
TAGS
Community showcase
Published in Jira

Do you use Jira Cloud with Microsoft Teams?

Hi, Jira users! Do you use Jira alongside Microsoft Teams? We want to hear how you’ve used the power of Jira Cloud and Microsoft Teams (via the Jira Cloud for Microsoft Teams app) to achieve a team...

400 views 2 6
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you