I am trying to create an automation that stores an issue key found within a comment. Currently I have the following:
ABC-{{comment.body.match("ABC-(\\d{1,6})")}}
Not sure why, but it sends the code twice e.g ABC-1234, 1234
It seems like it is writing down the same match twice (it is from a link so not sure if that affects).
Is there a way to prevent this so that I have ABC-1234 only? Thanks
Hi @Nadege
You appear to be extracting issue keys from a comment body. There are several things to handle for that scenario:
First, the match() function can have difficulty with comment formatting, such as newlines. Thus it makes sense to parse those out first, perhaps by using the replace function to convert them to spaces.
Next, your comment likely contains a smart link, and so a specific issue key could be found multiple times. That could be reduced using the distinct function: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-lists/#list.distinct
Finally, are you certain your comment contains one-and-only-one issue key? Perhaps it could contain several.
Putting those together, this expression would return the distinct keys found in the comment.
{{issue.comment.last.body.replace("\n", " ").match("([A-Z]+-\\d+)").distinct}}
Kind regards,
Bill
This works
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Comments loop over in an array. you should add a condition to break out of the loop when you get first match
refer this article and share the screen shot of your automation if you face challenges
https://community.atlassian.com/t5/Automation-articles/Filtering-smart-value-lists/ba-p/1827588
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the response.
Is this also the case when there is only one comment? (the comment it is reading from is the first comment).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
if there is only one comment and there is only item matching the pattern, then one value should be returned.
Can you share the screenshot of the rule that you have written so far?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Currently is something like the following:
It edits the field with the value I return above, but no matter how many tickets there are (be it one or multiple) with the same issue key, it always returns twice.
I believe it has something to do with the link that is reading from, as when I type in manually the automation works fine,
However, from the link (although within the actual link itself it only occurs once) it returns the value twice
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
one of the possible reasons that I can think of is your ABC-123 is getting converted into a hyperlink automatically and hence you are getting 2 values.
Can you check that?
Also, if your use case requires to check on latest comment then you can use this smart value {{issue.comments.last.body}}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.