In automation how to count number of URLs in description?

Mihail Turusov July 8, 2020

The goal is to count number of URL occurrences as plain text (number of "https://url.com...") and display those as a field. 

To start learning I tried creating a smart value the dumbest possible way {{issue.NumberOfEdits}} and on case edit {{#increment}}{{issue.NumberOfEdits}}{{/}} but it doesn't look as it works?..

1 answer

1 accepted

2 votes
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.
July 8, 2020

Hi @Mihail Turusov 

I have not heard of NumberOfEdits before.  Where did you see that one?

Another way to count those URLs is using the split function and counting the list items:

  • Trigger: value changes for Description
  • Condition: If/else structure...
    • If the Description field does not contain https, set the count to zero (0)
    • Else count the urls
{{#=}}{{issue.description.split("https").size}}-1{{/}}

How this works:

  • Split the description field on the text "https" into a list
  • Count the size of the list
  • Subtract one for extra list item from the split

 

Best regards,

Bill

Mihail Turusov July 10, 2020

Thank you for your reply. 

That smart value is something I tried to create myself (when ticket is created - create smart value) to later operate it and to learn about them more.

I tried the rule you suggested and am getting an error (replaced https with URL of app domain):

Error rendering smart-values when executing this rule:

Failed to get value for issue.description.split("[https://app.intercom").size: {{#=}}{{issue.description.split("[https://app.intercom").size}}-1{{/}}

Untitled.png

I believe I've done it properly?..

 

Also tried without a bracket and "https://" part and looks like it parses properly with it, but number is 2x as high (I believe because of doubled text and URL for text). Dividing it by 2 kinda work, but how do I modify the rule so it won't break for "[https://app.intercom" line?

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.
July 10, 2020

Hi @Mihail Turusov 

Short version is that you may need to experiment a bit with this...

There are reserved characters that the split() does not like, but I have been unable to find documentation for the valid/invalid list.  Perhaps they can be escaped, but I have not had success with that method.  That is why I only searched on "https" in my example.

One such reserved character is the period (.), and so when I need to split on that, I first perform a substitution and then split:

{{#=}}{{issue.description.replace(".", "ZZZ").split("ZZZ").size}}-1{{/}}

Perhaps you could perform some replacement of troublesome characters and then split using this method.

Like Mihail Turusov likes this
Mihail Turusov July 11, 2020

This is super helpful! thank you!

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