How can I count the lines of a custom field or the length of a list?

Nicolas Mezou February 12, 2021

Hi,

I have a custom field, where we enter the names of all customers who are interested in a feature. This is great to see who to contact, before conceptualizing a new feature. But I would also like to get some quantitative insights about how many customers are interested. So I would like to count the line of the custom field. Currently, we use unordered lists:

  • customer 1
  • customer 2
  • customer 3

If I could get the length of the list, or the count of lines I would directly receive the number of interested customers.

I tried a workaround by just using the `{{issue.Interested Customer.length}}` but it returns the length of the entire string which is not really representative.

Does anybody have an idea how to solve this.

1 answer

1 accepted

1 vote
Answer accepted
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.
February 12, 2021

Hi @Nicolas Mezou  -- Welcome to the Atlassian Community!

First thing: thanks for this question, as it helped me find a new defect in the automation rule conditions... Once a text field has been set, it cannot show as "is empty" ever again.  (I will submit a defect for that.)

On to your question... I did this counting by splitting the text and counting the new line characters.  Here is an example rule putting the customer list in Description and logging the results.

  • Trigger: manual, or whatever you need
  • If/Else, Advanced Condition: {{issue.description.length}} equals 0
    • Action: log that the count is zero
  • Else, Advanced Condition:  {{issue.description.length}} is greater than 0
    • Action: log that line count is {{issue.description.split(".*\n").size}}

Note that when there is only one customer (one bullet), the count should still be correct even though there is no new-line character.  That seems to be a behavior of split() returning the unmatched string.

Best regards,

Bill

Nicolas Mezou February 13, 2021

Awesome, thank you so much @Bill Sheboy !

Like Bill Sheboy likes this

Suggest an answer

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

Atlassian Community Events