Forums

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

I want to make a automation that send a slack message with mention when mentioned in the comment

藤野 珠輝 December 26, 2023

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.
コメント 2023-12-27 164614.jpg

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.

2 answers

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.
December 27, 2023

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:

  • action: Create Lookup Table, with a row for each user.  The "key" would be their account id and the "value" would be their Slack id.  Let's assume that is named tblSlackUserList
  • action: Create Variable to extract all of the mentioned users' account id values into a comma-separated values list.  Let's assume that is named varUserList
  • advanced branch: to split your created variable into each item for looping with {{varUserList.split(",")}}  Let's assume the variable is varUser
    • action: send your Slack message to the user, getting their Slack id with:
      • {{tblSlackUserList.get(varUser)}}

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

藤野 珠輝 February 18, 2024

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.

slackrule.png

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 19, 2024

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.

藤野 珠輝 February 20, 2024

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:

Error rendering smart-values when executing this rule:
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.

コメント 2024-02-20 193501.png

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 20, 2024

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}}

 

 

藤野 珠輝 February 26, 2024

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!
1.pngコメント 2024-02-27 105426.png2.png3.png

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 27, 2024

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().

藤野 珠輝 February 28, 2024

Hi Bill,

Thank you so much for your suggestion. It worked like a charm!!
I cannnot appreciate you enough!

Like # people like this
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 28, 2024

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!

Like # people like this
0 votes
藤野 珠輝 December 26, 2023

Forgot to mention -

my Jira project is controlled by my company so I cannot do some setting that needs organization admin.

Suggest an answer

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

Atlassian Community Events