Need to add all the users mentioned in the comment to the custom field

Martin Fukatko June 23, 2022

Hi, I need to add all the users mentioned in created comment to custom field Cooperators. 

Cooperators is a field with type "User Picker (multiple users)".

 

How to do it in Jira automation?

Thanks in advance for any suggestions.

1 answer

1 accepted

0 votes
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.
June 23, 2022

Hi @Martin Fukatko 

A couple of ways to do this are with an advanced, smart value branch to loop and with a single edit:

  • Loop: Use a regular expression with match() to parse the users' account ID values out of the comment, and then use that result as the input for an advanced branch.  Within the branch use an advanced edit with JSON to add the user to the field.
  • One step: Use the regular expression to parse the users' account ID values, wrapping the result with the proper syntax to add them all at once using a JSON edit.

Please consider if you want to clear or add to existing Cooperator values if multiple comments occur.

This is a complicated rule to write, so I recommend doing it one step at a time and writing the intermediate results to the audit log before making any edits to the issue.

Kind regards,
Bill

Martin Fukatko June 24, 2022

@Bill Sheboy 

Bill, thank you for answer.

Don't you have an example for "regular expression with match() to parse the users' account ID values out of the comment" ?

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.
June 24, 2022

Hi, Martin.

Writing automation rules often requires experimentation.  I encourage you to try things, such as writing comments to the audit log, to learn more about how Jira implements things like mentions...as that will give you ideas for how to parse them with regular expressions.

To get you started, this expression will return a list of user account ID values for the last comment added:

{{issue.comment.last.body.split("\n").match("\[~accountid:(.*)\].*")}}

Kind regards,
Bill

krunoslav.majer November 14, 2023

Hi @Bill Sheboy 

already over a year old but I found your proposal and started using it but then I realized that the RegEx isn't fully correct and I am struggeling to get there - maybe you can/want to have a look?

The issue is that if there are multiple accountIds with text inbetween like "," or "and" they end up in the result as well as the regex doesn't stop for each accountId.

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.
November 14, 2023

Hi @krunoslav.majer 

First, for an older thread like this, I recommend creating a new question and linking back to the older one.  That will ensure the most number of people see it to help.  Otherwise only the people following the old threads see them.  Thanks!

Without seeing the details of your rule and a sample of your text with mentions...I suspect this is more of the challenges in the regular expression implementation for automation rules.  The documentation describes they are "based on Java's Pattern class and uses Matcher.find() to find matches".  However they do not describe what does / does not work the same.

In my earlier post, I suggested splitting on newlines to help the match() reduce the scope of match attempts.  That might help for your case.  I just retested with mentions separated by commas and "and" and the matches found all of them.

Kind regards,
Bill

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events