How to check all items closed in a groovy condition?

Martin Heini December 15, 2021

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
David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 15, 2021

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)
Martin Heini December 16, 2021

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.

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 16, 2021

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

Martin Heini December 22, 2021

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
}  
David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 22, 2021

@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
Martin Heini December 23, 2021

Hi David

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

Martin

0 votes
Olena Brazhko_Railsware_
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.
December 17, 2021

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