Automation - mentioned user into a smart value variable to edit issue field
Asked by Jisoo Kim:

Hi, I am new to Jira, not a developer nor a system admin etc.... and struggling with automation rules.

What I am trying to do is:

1) When issue is commented,

2) If issue's comment contains a mentioned user, and a certain word,

3) Edit assignee and a custom field(user) to mentioned user.

So far, my automation rules look like this :

1) Trigger : When issue is commented,

2) If : (Advanced compare condition) Checks if : {{commebt.body}} contains regular expression \[\~accountid:XYZ\]

3) Then : Create Varible {{mentionedUser}}, smart value : {{issue.comment.last.body.split("\\n").match(\\\[\~accountid"(.\*)\\\].\*")}}

4) (Then) And : Edit issue field Assignee : {{mentionedUser}}

And not working.

It seems like create variable is not getting the text strings from the comment, nor the split match etc. Is working as the varible {{mentionedUser}} returns empty space " ".

Can anyone please help );

Thank yoh in advance.


Answers:
author: Radek Dost?l
body: This gave me a bit of a headache but <https://jira.atlassian.com/browse/JIRAAUTOSERVER-489> was the "oh I get this now.."

I will need to mention that I toggled on 'Execute this rule immediately' because otherwise it seemed the rule wouldn't trigger for new comments, waited a while.

That said, I do see couple things that need a slight programming thought, when you do regular expressions, there are plenty "special characters" you might need to escape. There is a list of them in the documentation (namely: the java Pattern) but this is what seems to work for me now:

**Advanced compare condition:**

```
\[~\w+\]
```

Why - because \[\] are special characters, and \\w indicates any regular word character, a-zA-Z0-9 that I expect a username to consist of.

Second: I am on server, meaning the user reference is \[\~username\]; the accountId you include is for cloud (I'm not sure whether you're on dc or cloud but the user references are different).

In any case, if you open

```
{jiraurl}/rest/api/latest/issue/<issuekey>?fields=comment
```

then you can see what the syntax should be like in your case.

**Create variable:**

```
{{comment.body.match("\[~(\w+)\]")}}
```

The only difference is the () brackets, that's what I wasn't getting for a while until I started looking for bugs. The () indicates the match we want, so it returns specifically the username in the variable. No need to split/cut/trim/match again.

As for what you are trying to do with this next, I don't think that you can just pass the username as an assignee - because assignee should expect a user key, not username, so I don't think that will work.

I don't see any.. obvious way to do it though, at most for now I can get the regex/variable to work, but I'm not sure how to use the plain text username to edit the assignee, and I'm sort of doubting it can be used at all. I suspect this approach won't work. Personally I would start looking at other scripted approaches (either integrated into A4J such as scriptrunner, or pretty much anything else really, like a custom listener even). I'm not in general a fan of the idea for this automation rule though, as it seems like it has plenty loopholes, and I don't know what options your instance has (your local admin should know what could be used here though).

comments: author: Jisoo Kim
body: Thank you! It worked!


author: Carla Ann Rowland
body: I would craft this-- this is draft because I cannot test my logic---

Trigger : when issue is commented

If summary \~ "key word" then JQL: (summary \~"@mention user")

then edit the issue

assignee set to the [@mention](/t5/user/viewprofilepage/user-id/732788) user

comments: author: Jisoo Kim
body: Thanks for the response,

But that's exactly where I am stuck in.

Idk how to get [@mention](/t5/user/viewprofilepage/user-id/732788) user to the field.

I've seen a lot of community posts regarding this, and many suggested to try create a variable with a smart value, something like :

{{issue.comments.last.body.match("\\\[accountid: . . . }}

However, I'm on DC so mayb it's a lil different.

I noticed that mentioning a user in my jira, u need to use :

\[\~{{username}}\]

So i'm guessing thay I need to get the comment's mentioned user by substring? Or split idk and only grab the username without \[\~{ etc special characters.


Tags: automation

custom-field

data-center

jira-service-management

jira-service-management-data-center

mention

smart-value

variable