Forums

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

A field that counts the number of pattern based labels

Marc Jason Mutuc
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.
June 2, 2020

Here are the sample labels on a ticket
ABC-1.234.0.1
ABC-1.567.0.0
ABC-2.345.9.0
EGF
XYZ

I plan to count labels with ABC-X.XXX.1-9.X

So the field should return 1 because of ABC-2.345.9.0

I can't seem to get things to work. Please help.

I've scriptrunner, jmcf, and jwt. :)

2 answers

0 votes
David Fischer
Community Champion
June 3, 2020

Using as JMCF Calculated Number field, the formula would be:

issue.get("labels")?.count{it.label ==~ /TC-[0-9]\.[0-9][0-9][0-9]\.[1-9]\.[0-9]/}

Note that your JWT regular expression is somewhat incorrect, as "." stands for "any character", not the "." character. Also, you don't need the parentheses. 

Marc Jason Mutuc
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.
June 4, 2020

Thanks David! I'll try this one as well.

0 votes
Marc Jason Mutuc
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.
June 3, 2020

Resolved using Calculated Text Field by JWT.

toString(count(findPattern(toString([%{Labels}]), "TC-([0-9]).([0-9][0-9][0-9]).([1-9]).([0-9])")))

Suggest an answer

Log in or Sign up to answer