Forums

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

Scriptrunner - Parse comment with regex and send custom mail to recipients in comment

AB March 23, 2021

Hi,

unfortunately, I have not yet found a suitable answer, so I ask my question directly here:

- Once a comment is created, the comment content should be parsed to users mentioned as @mention.
- If a @mention is found, it should be checked if the user belongs to a certain project role or not.
- If the condition is met (@mention belongs to role), a mail should be sent to this user.

I thought that the rubric "Listener" would fit to this, but you can only store fixed mail addresses there.

What is the best way to proceed?

Thanks!

1 answer

0 votes
PD Sheehan
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.
March 23, 2021

Actually, no, you don't have to rely on the fixed email address using the "Send a custom email" script listener.

You can use the "Condition and Configuration" script to set your recipients.

In that script, there is a "mail" variable in the binding.

So you can parse the comment there and then set mail.setTo("your recipients")

Note that when parsing your comment, you'll want to look for [~userName] not @DisplayName since the body of the comment is the underlying wiki format.

Another possibility to explore is to use a "Custom Listener" which allows you to Listen to the "MentionIssueComment" which has a built-in "toUsers()" method that contains the list of users mentioned in the comment.

But that means you would have to code your own interactions with the jira mail systems.

So 2 approaches:

  1. Code your own parsing and leverage the built-in scrirptrunner mail creation
  2. Use the built-in parsing and code your own mail sending

Suggest an answer

Log in or Sign up to answer