Forums

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

Count times a string appears in a label

Menia Laina
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!
January 17, 2025

Hello, I'm trying to count how many dates of format 

YYYY_Tx

exist in a Labels field and save this as a numeric value in another field. I try the below, but I keep getting erros. Any help on what is wrong? So the Labels has: 2024_T3 , 2025_T1 , etc

The error I get: 

Unable to render smart values when executing this rule:

Failed to get value for issue.Labels.match('.*(\\d{4}_T\\d).*').size: { "fields": { "Overall effort": "{{issue.Labels.match('.*(\\d{4}_T\\d).*').size}}" } }
the expression I put in the edit issue field (to update the Overall effort numeric field): 

{ "fields": { "Overall effort": "{{issue.Labels.match('.*(\\d{4}_T\\d).*').size}}" } }

2 answers

1 vote
Renata_Getint
Atlassian Partner
January 20, 2025

Hi @Menia Laina

 

To count how many labels in the format YYYY_Tx exist in your Labels field and save the count in another field, your current smart value expression is close but has a slight issue.

The Fix

The match function is being applied incorrectly in your smart value expression. Instead of using .match to count occurrences, you should use .filter to isolate the labels matching the desired format and then count them using .size.

Here’s the corrected expression:

{
"fields": {
"Overall effort": "{{issue.labels.filter(label -> label.match('\\d{4}_T\\d')).size}}"
}
}

 

Explanation

  • issue.labels: Refers to the Labels field, which is a list of strings.
  • .filter(label -> label.match('\\d{4}_T\\d')): Filters the labels, keeping only those matching the format YYYY_Tx using a regex pattern.
  • .size: Counts the number of matching labels.

Steps to Implement

  1. Edit your automation rule.
  2. Use the above expression in the "Edit issue" action for updating the Overall effort field.
  3. Test the rule with sample data to ensure it works as expected.

Let us know if you need further clarification or additional help! At Getint, we specialize in integrations and optimizing workflows, so feel free to reach out for guidance.

Bill Sheboy
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.
January 20, 2025

Hi @Renata_Getint 

What is the source of the content you posted?

If it is from a bot / AI-tool, please see the community guidelines regarding the disclosure of such content in your post's wording:

https://community.atlassian.com/t5/custom/page/page-id/rules-of-engagement

Kind regards,
Bill

Janice
Community Manager
Community Managers are Atlassian Team members who specifically run and moderate Atlassian communities. Feel free to say hello!
January 20, 2025

@Renata_Getint We noticed this response has a distinct AI-like formatting. While we're all for embracing new tech, we want remind everyone of the Atlassian community guidelines and Responsible Tech Principles. Put simply, AI can be a great tool for polishing, but your real-world knowledge is what our community values most. We ask the core of your contributions to come from your own expertise.

 
If you do use AI in your responses the community management team asks members disclose this in responses. We're all about transparency and genuine human connections here. If you have any questions about this, feel free to reach out to communitymanagers@atlassian.com.
1 vote
Bill Sheboy
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.
January 17, 2025

Hi @Menia Laina -- Welcome to the Atlassian Community!

The problem is the use of single-quotation marks, as the match() function expression takes double-quotation marks.

 

What is the type of your field: numeric or text?

If the field is numeric, please change the expression to this:

{
"fields": {
"Overall effort": {{issue.Labels.match(".*(\\d{4}_T\\d).*").size}}
}
}

If the field is text, either:

  • first store the result with Create Variable and then use that variable in the expression
  • or convert the value to text with format() and then add asJsonString to the end to wrap it in quotation marks.

 

Kind regards,
Bill

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events