Hi,
I am trying to make an automation rule that does below:
- Triger: When commented
- If: the comment includes mention
- Then: send a slack message with mention to the specific user mentioned in the jira comment
---------------------------------
Currently the rule I made look like the picture below.
This automation works but the problem is the use of if-else condition.
When one of the if-condition is met, the following if-conditions are ignored. Therefore, this rule does not work when I want to mention more than one person.
Are there anyway to fix this? Also, I know the way I made the rule is not very practical, so I am looking for the way to simplify the rule by using variables or look up table.
I appreciate any help! Thank you in advance.
Hi @藤野 珠輝 -- Welcome to the Atlassian Community!
Rather than using an if / else structure, you can simplify your rule to use a Created Table, Created Variable, and Advanced Branch. For example:
This method will work for up to 200 users, as that is the current limit for the Lookup Table.
Here is more documentation on those techniques to learn more:
Kind regards,
Bill
Hi Bill,
Thank you so much for your answer and sorry for my late response.
I built the rule based on your suggestion.
I am not sure what to put on the smart value for varUserList, to make a comma-separated list.
I attached the picture of the current rule. I really appreciate if you can spot when I should change - currently even if the user in the look up table is mentioned, slack message will not be sent.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Consider adding a split(" ") before the match to improve the chances of a match when there are newlines and other formatting in the comment. They try re-testing.
If that does not help, please post an image of the updated rule and the audit log details from the rule execution.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you. I tried to follow your advice but since I define "varUser" in Advanced branching using "varUserList" so thought it is not possible to put split before the match. Can you explain a little more about what you meant?
Also, I removed "if: compare two values" then, audit log shows an error:
Failed to get value for issue.comment.last.body.match("\[~accountid:(.*)\]): {{issue.comment.last.body.match("\[~accountid:(.*)\])}}
it seems the smart value in Create variable is wrong. Do you have any idea how I should fix this?
Thank you in advance.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
First, your regular expression in the match() is missing the closing quotation mark, which is causing that error.
Here is the expression I suggested, and I added distinct at the end. That will handle cases where the same user is mentioned multiple times in the same comment.
{{issue.comment.last.body.split(" ").match("\[~accountid:(.*)\]").distinct}}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you Bill.
Now successfully I got multiple messages sent in slack when multiple users mentioned in the Jira comment.
I still have one issue. Only the first value in the lookup table is correctly appeared in the slack messages.
Let's say I have two users (the first picture), and I mentioned them in a comment.
But slack messages look like the second picture. Only the first value is correctly sent.
Any idea where I should fix this? I attached the smart value for branch (the third picture) and the content of slack message (the fourth picture).
I really appreciate your help!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Okay, I removed the prior message, as here is the problem:
{{issue.comment.last.body.split(" ").match("\[~accountid:(.*)\]").distinct}}
The result of that expression is a list...but we stick it into a variable. That then joins the values with commas AND adds spaces to make it more people-friendly for reading.
As a result, each variable (after the first one) in the advanced branch as a leading space.
We wanted that expression without extra spaces as input for processing, and so we can override by explicitly adding our own join:
{{issue.comment.last.body.split(" ").match("\[~accountid:(.*)\]").distinct.join(",")}}
That will make input that can cleanly be handled by the advanced branch's use of split().
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Awesome; I am glad to learn that helped!
If this solves the remaining questions, please consider marking this one "answered" as that will help others with similar needs find solutions faster. Thanks!
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.